Safe Haskell | None |
---|---|
Language | Haskell98 |
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
- 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 ()
- union :: Query a -> Query b -> Query Pattern
- union_ :: Query a -> Query b -> Query ()
- exists :: Query a -> Query Pattern
- notExists :: Query a -> Query Pattern
- filterExpr :: TermLike a => a -> Query Pattern
- filterExpr_ :: TermLike a => 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
- 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.
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.
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 #
select :: [SelectExpr] -> Query SelectQuery Source #
selectVars :: [Variable] -> Query SelectQuery Source #
as :: Expr -> Variable -> SelectExpr Source #
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
SubjectTermLike BlankNodePattern Source # | |
Defined in Database.HSparql.QueryGenerator | |
SubjectTermLike Variable Source # | |
Defined in Database.HSparql.QueryGenerator |
class TermLike a => PredicateTermLike a Source #
Restriction of TermLike to the role of predicate.
Instances
PredicateTermLike Variable Source # | |
Defined in Database.HSparql.QueryGenerator |
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 |