Safe Haskell | None |
---|---|
Language | Haskell2010 |
The query generator DSL for SPARQL, used when connecting to remote endpoints.
Synopsis
- createSelectQuery :: Query SelectQuery -> String
- createConstructQuery :: Query ConstructQuery -> String
- createAskQuery :: Query AskQuery -> String
- createUpdateQuery :: Query UpdateQuery -> String
- createDescribeQuery :: Query DescribeQuery -> String
- prefix :: Text -> IRIRef -> Query Prefix
- var :: Query Variable
- embeddedTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> EmbeddedTriple
- triple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern
- triple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query ()
- mkPredicateObject :: (PredicateTermLike a, ObjectTermLike b, QueryShow a, QueryShow b, Show a, Show b) => a -> b -> DynamicPredicateObject
- constructTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern
- constructTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query ()
- askTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern
- askTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query ()
- updateTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern
- updateTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query ()
- describeIRI :: IRIRef -> Query IRIRef
- describeIRI_ :: IRIRef -> Query ()
- optional :: Query a -> Query Pattern
- optional_ :: Query a -> Query ()
- service :: IRIRef -> Query a -> Query Pattern
- service_ :: IRIRef -> Query a -> Query ()
- union :: Query a -> Query b -> Query Pattern
- union_ :: Query a -> Query b -> Query ()
- filterExpr :: TermLike a => a -> Query Pattern
- filterExpr_ :: TermLike a => a -> Query ()
- filterExists :: Query a -> Query Pattern
- filterExists_ :: Query a -> Query ()
- filterNotExists :: Query a -> Query Pattern
- filterNotExists_ :: Query a -> Query ()
- bind :: Expr -> Variable -> Query Pattern
- bind_ :: Expr -> Variable -> Query ()
- subQuery :: Query SelectQuery -> Query Pattern
- subQuery_ :: Query SelectQuery -> Query ()
- select :: [SelectExpr] -> Query SelectQuery
- selectVars :: [Variable] -> Query SelectQuery
- as :: Expr -> Variable -> SelectExpr
- a :: PathLengthOne
- (.//.) :: (PropertyPathExprLike a, PropertyPathExprLike b) => a -> b -> PropertyPathExpr
- (.|.) :: (PropertyPathExprLike a, PropertyPathExprLike b) => a -> b -> PropertyPathExpr
- (..|..) :: (NegativePropertySetLike a, NegativePropertySetLike b) => a -> b -> NegativePropertySet
- inv :: PropertyPathExprLike a => a -> PropertyPathExpr
- (*.) :: PropertyPathExprLike a => a -> PropertyPathExpr
- (+.) :: PropertyPathExprLike a => a -> PropertyPathExpr
- (?.) :: PropertyPathExprLike a => a -> PropertyPathExpr
- neg :: NegativePropertySet -> PropertyPathExpr
- inv' :: NegativePropertySetLike a => a -> NegativePropertySet
- distinct :: Query Duplicates
- distinct_ :: Query ()
- reduced :: Query Duplicates
- reduced_ :: Query ()
- limit :: Int -> Query Limit
- limit_ :: Int -> Query ()
- groupBy :: TermLike a => a -> Query [GroupBy]
- groupBy_ :: TermLike a => a -> Query ()
- orderNext :: TermLike a => a -> Query ()
- orderNextAsc :: TermLike a => a -> Query ()
- orderNextDesc :: TermLike a => a -> Query ()
- (.:.) :: Prefix -> Text -> IRIRef
- iriRef :: Text -> IRIRef
- (.+.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.-.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.*.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (./.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.&&.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.||.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.==.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.!=.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.<.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.>.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.<=.) :: (TermLike a, TermLike b) => a -> b -> Expr
- (.>=.) :: (TermLike a, TermLike b) => a -> b -> Expr
- notExpr :: TermLike a => a -> Expr
- count :: BuiltinFunc1
- sum_ :: BuiltinFunc1
- min_ :: BuiltinFunc1
- max_ :: BuiltinFunc1
- avg :: BuiltinFunc1
- groupConcat :: TermLike a => a -> String -> Expr
- str :: BuiltinFunc1
- lang :: BuiltinFunc1
- langMatches :: BuiltinFunc2
- datatype :: BuiltinFunc1
- bound :: Variable -> Expr
- sameTerm :: BuiltinFunc2
- isIRI :: BuiltinFunc1
- isURI :: BuiltinFunc1
- isBlank :: BuiltinFunc1
- isLiteral :: BuiltinFunc1
- regex :: BuiltinFunc2
- regexOpts :: BuiltinFunc3
- strlen :: BuiltinFunc1
- substr :: BuiltinFunc1
- ucase :: BuiltinFunc1
- lcase :: BuiltinFunc1
- strstarts :: BuiltinFunc2
- strends :: BuiltinFunc2
- contains :: BuiltinFunc2
- strbefore :: BuiltinFunc2
- strafter :: BuiltinFunc2
- abs_ :: BuiltinFunc1
- round_ :: BuiltinFunc1
- ceil :: BuiltinFunc1
- floor_ :: BuiltinFunc1
- concat_ :: BuiltinFunc2
- replace :: BuiltinFunc3
- rand :: BuiltinFunc0
- qshow :: QueryShow a => a -> String
- type Query a = State QueryData a
- data Prefix
- data Variable
- data VarOrNode
- type BlankNodePattern = [DynamicPredicateObject]
- data Pattern
- data SelectQuery = SelectQuery {
- queryExpr :: [SelectExpr]
- data SelectExpr
- = SelectExpr Expr Variable
- | SelectVar Variable
- data ConstructQuery = ConstructQuery {
- queryConstructs :: [Pattern]
- data AskQuery = AskQuery {}
- data UpdateQuery = UpdateQuery {
- queryUpdate :: [Pattern]
- data DescribeQuery = DescribeQuery {
- queryDescribe :: IRIRef
- class TermLike a where
- class TermLike a => SubjectTermLike a
- class TermLike a => PredicateTermLike a
- class TermLike a => ObjectTermLike a
Creating Queries
createSelectQuery :: Query SelectQuery -> String Source #
Execute a 'Select Query' action, returning the String
representation of the query.
createConstructQuery :: Query ConstructQuery -> String Source #
Execute a 'Construct Query' action, returning the String
representation of the query.
createAskQuery :: Query AskQuery -> String Source #
Execute a 'Ask Query' action, returning the String
representation of the query.
createUpdateQuery :: Query UpdateQuery -> String Source #
Execute a 'Update Query' action, returning the String
representation of the query.
createDescribeQuery :: Query DescribeQuery -> String Source #
Execute a 'Describe Query' action, returning the String
representation of the query.
Query Actions
prefix :: Text -> IRIRef -> Query Prefix Source #
Add a prefix to the query, given an IRI reference, and return it.
var :: Query Variable Source #
Create and return a variable to the query, usable in later expressions.
embeddedTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> EmbeddedTriple Source #
Create an embedded triple usable in an expression. See SPARQL* at https://wiki.blazegraph.com/wiki/index.php/Reification_Done_Right or https://arxiv.org/abs/1406.3399.
triple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern Source #
Restrict the query to only results for which values match constants in this triple, or for which the variables can be bound.
triple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query () Source #
mkPredicateObject :: (PredicateTermLike a, ObjectTermLike b, QueryShow a, QueryShow b, Show a, Show b) => a -> b -> DynamicPredicateObject Source #
support for blank nodes.
Define a convenient alias for mkPredicateObject
. Note: a
pointfree definition leads to the monomorphism restriction (&) =
mkPredicateObject
. An example of its use:
p & o = mkPredicateObject p o
for example
q = do p <- prefix "" (iriRef "http://example.com/") s <- var o1 <- var o2 <- var _ <- triple s (p .:. "p1") [(p .:. "p2") & [(p .:. "p3") & o1], (p .:. "p4") & o2] return SelectQuery { queryVars = [s, o1] }
>>>
createSelectQuery q
"PREFIX : <http://example.com/> SELECT ?x0 ?x1 WHERE {?x0 :p1 [:p2 [:p3 ?x1]], [:p4 ?x2] .} "
constructTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern Source #
constructTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query () Source #
askTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern Source #
askTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query () Source #
updateTriple :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query Pattern Source #
updateTriple_ :: (SubjectTermLike a, PredicateTermLike b, ObjectTermLike c) => a -> b -> c -> Query () Source #
describeIRI :: IRIRef -> Query IRIRef Source #
describeIRI_ :: IRIRef -> Query () Source #
optional :: Query a -> Query Pattern Source #
Add optional constraints on matches. Variable bindings within the optional action are lost, so variables must always be defined prior to opening the optional block.
:: IRIRef | SPARQL endpoint |
-> Query a | SPARQL query to invoke against a remote SPARQL endpoint |
-> Query Pattern |
Instruct a federated query processor to invoke the portion of a SPARQL query against a remote SPARQL endpoint.
For example
createQuery $ do foaf <- prefix "foaf" (iriRef "http://xmlns.com/foaf/0.1/") person <- var name <- var triple_ (iriRef "http://example.org/myfoaf/I") (foaf .:. "knows") person _ <- service (iriRef "http://people.example.org/sparql") $ do triple_ person (foaf .:. "name") name selectVars [name]
produces the SPARQL query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?x1 WHERE { <http://example.org/myfoaf/I> foaf:knows ?x0 . SERVICE <http://people.example.org/sparql> { ?x0 foaf:name ?x1 . } }
service_ :: IRIRef -> Query a -> Query () Source #
Same as service
, but without returning the query patterns.
union :: Query a -> Query b -> Query Pattern Source #
Add a union structure to the query pattern. As with optional
blocks,
variables must be defined prior to the opening of any block.
filterExpr :: TermLike a => a -> Query Pattern Source #
Restrict results to only those for which the given expression is true.
filterExpr_ :: TermLike a => a -> Query () Source #
filterExists_ :: Query a -> Query () Source #
filterNotExists_ :: Query a -> Query () Source #
select :: [SelectExpr] -> Query SelectQuery Source #
selectVars :: [Variable] -> Query SelectQuery Source #
as :: Expr -> Variable -> SelectExpr Source #
Property paths
SPARQL 1.1 property paths documentation: https://www.w3.org/TR/sparql11-query/#propertypaths
Binary operators
Property path binary operators
(.//.) :: (PropertyPathExprLike a, PropertyPathExprLike b) => a -> b -> PropertyPathExpr infixl 5 Source #
Creating a property path sequence.
>>>
IRIRef "rdf:type" ./. IRIRef "rdfs:subClassOf" ./. IRIRef "rdfs:subClassOf"
rdf:type/rdfs:subClassOf/rdfs:subClassOf
(.|.) :: (PropertyPathExprLike a, PropertyPathExprLike b) => a -> b -> PropertyPathExpr infixl 4 Source #
Creating an alternative property path.
>>>
IRIRef "rdfs:label" .|. IRIRef "foaf:name" .|. IRIRef "foaf:givenName
rdfs:label|foaf:name|foaf:givenName
Negative property set binary operators
(..|..) :: (NegativePropertySetLike a, NegativePropertySetLike b) => a -> b -> NegativePropertySet infixl 4 Source #
Creating an alternative property path inside a negative property set.
>>>
neg $ IRIRef "rdfs:label" ..|.. IRIRef "foaf:name" ..|.. IRIRef "foaf:givenName"
!(rdfs:label|foaf:name|foaf:givenName)
Unary operators
Property path unary operators
inv :: PropertyPathExprLike a => a -> PropertyPathExpr Source #
Creating an inverse property path.
>>>
inv (IRIRef "foaf:mbox")
^foaf:mbox
(*.) :: PropertyPathExprLike a => a -> PropertyPathExpr Source #
Creating a zero or more path.
>>>
IRIRef "rdf:type" ./. ((IRIRef "rdfs:subClassOf") *.)
rdf:type/rdfs:subClassOf*
(+.) :: PropertyPathExprLike a => a -> PropertyPathExpr Source #
Creating a one or more path.
>>>
((IRIRef "foaf:knows") +.) ./. IRIRef "foaf:name"
foaf:knows+/foaf:name
(?.) :: PropertyPathExprLike a => a -> PropertyPathExpr Source #
Creating a zero or one path.
>>>
rdfType ./. (rdfsSubClassOf ?.)
rdf:type/rdfs:subClassOf?
Negative property set unary operators
neg :: NegativePropertySet -> PropertyPathExpr Source #
Creating a negative property set.
>>>
inv foafMbox
^foaf:mbox
inv' :: NegativePropertySetLike a => a -> NegativePropertySet Source #
Creating an inverse path of length one inside a negative property set.
>>>
neg $ IRIRef "rdfs:label" ..|.. IRIRef "foaf:name" ..|.. (inv' $ IRIRef "foaf:givenName")
!(rdfs:label|foaf:name|^foaf:givenName)
Duplicate handling
distinct :: Query Duplicates Source #
Set duplicate handling to Distinct
. By default, there are no reductions.
reduced :: Query Duplicates Source #
Set duplicate handling to Reduced
. By default, there are no reductions.
Limit handling
limit :: Int -> Query Limit Source #
Set limit handling to the given value. By default, there are no limits. Note: negative numbers cause no query results to be returned.
Groups handling
Order handling
orderNextAsc :: TermLike a => a -> Query () Source #
Order the results, after any previous ordering, based on the term, in ascending order.
orderNextDesc :: TermLike a => a -> Query () Source #
Order the results, after any previous ordering, based on the term, in descending order.
Auxiliary
Term Manipulation
Operations
(.-.) :: (TermLike a, TermLike b) => a -> b -> Expr infixl 6 Source #
Find the difference between two terms.
(.&&.) :: (TermLike a, TermLike b) => a -> b -> Expr infixr 3 Source #
Combine two boolean terms with AND
(.||.) :: (TermLike a, TermLike b) => a -> b -> Expr infixr 2 Source #
Combine two boolean terms with OR
Relations
(.==.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their equivalence.
(.!=.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their equivalence.
(.<.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their relative value.
(.>.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their relative value.
(.<=.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their relative value.
(.>=.) :: (TermLike a, TermLike b) => a -> b -> Expr infix 4 Source #
Create an expression which tests the relationship of the two operands, evaluating their relative value.
Negation
notExpr :: TermLike a => a -> Expr Source #
Negate any term-like expression, for use, e.g., in filtering.
Builtin aggregation functions
groupConcat :: TermLike a => a -> String -> Expr Source #
Aggregate a column by string concatenation with a separator.
Builtin Functions
langMatches :: BuiltinFunc2 Source #
strstarts :: BuiltinFunc2 Source #
strstarts ( string x ) - return true if x matches the beginning of string
contains :: BuiltinFunc2 Source #
contains ( string x ) - return true if x matches anywhere in string
Printing Queries
qshow :: QueryShow a => a -> String Source #
Convert most query-related types to a String
, most importantly
QueryData
s.
Types
Instances
Enables programmatic construction of triples where it is not known in
advance which parts of the triple will be variables and which will be
Node
s.
type BlankNodePattern = [DynamicPredicateObject] Source #
data SelectQuery Source #
data SelectExpr Source #
Instances
Show SelectExpr Source # | |
Defined in Database.HSparql.QueryGenerator showsPrec :: Int -> SelectExpr -> ShowS # show :: SelectExpr -> String # showList :: [SelectExpr] -> ShowS # |
data UpdateQuery Source #
data DescribeQuery Source #
DescribeQuery | |
|
Classes
class TermLike a where Source #
Permit variables and values to seemlessly be put into argument for triple
and similar functions
Instances
TermLike Bool Source # | |
TermLike Integer Source # | |
TermLike Text Source # | |
TermLike Node Source # | |
TermLike VarOrNode Source # | |
TermLike BlankNodePattern Source # | |
Defined in Database.HSparql.QueryGenerator varOrTerm :: BlankNodePattern -> VarOrTerm Source # expr :: BlankNodePattern -> Expr Source # | |
TermLike Variable Source # | |
TermLike (Text, Text) Source # | |
class TermLike a => SubjectTermLike a Source #
Restriction of TermLike to the role of subject.
Instances
class TermLike a => PredicateTermLike a Source #
Restriction of TermLike to the role of predicate.
Instances
class TermLike a => ObjectTermLike a Source #
Restriction of TermLike to the role of object.
Instances
ObjectTermLike Bool Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike Integer Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike Text Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike Node Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike VarOrNode Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike BlankNodePattern Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike Variable Source # | |
Defined in Database.HSparql.QueryGenerator | |
ObjectTermLike (Text, Text) Source # | |
Defined in Database.HSparql.QueryGenerator |