public class QueryStringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static IRI |
BNODE_URI
A dummy URI which is used as a replacement for
BNode s in appendBNode(StringBuilder, BNode) since
BNodes cannot be expressed in SPARQL queries |
Constructor and Description |
---|
QueryStringUtil() |
Modifier and Type | Method and Description |
---|---|
protected static StringBuilder |
appendBNode(StringBuilder sb,
BNode bNode)
Append a dummy string (see
BNODE_URI ) to represent the BNode. |
protected static StringBuilder |
appendLiteral(StringBuilder sb,
Literal lit)
Append the literal to the stringbuilder.
|
protected static StringBuilder |
appendURI(StringBuilder sb,
IRI uri)
Append the uri to the stringbuilder, i.e.
|
protected static StringBuilder |
appendValue(StringBuilder sb,
Value value)
Append a string representation of the value to the string builder.
|
protected static StringBuilder |
appendVar(StringBuilder sb,
Var var,
Set<String> varNames,
BindingSet bindings)
Append the variable to the provided StringBuilder.
|
protected static StringBuilder |
appendVarId(StringBuilder sb,
Var var,
String varID,
Set<String> varNames,
BindingSet bindings)
Append the variable to the provided StringBuilder, however change name of variable by appending "_varId" to it.
|
static String |
askQueryString(ExclusiveTupleExpr expr,
BindingSet bindings,
Dataset dataset)
Transform the
ExclusiveTupleExpr into a ASK query string |
static String |
askQueryString(StatementPattern stmt,
BindingSet bindings,
Dataset dataset)
Construct a boolean ASK query for the provided statement.
|
protected static String |
constructInnerUnion(StatementPattern stmt,
int outerID,
Set<String> varNames,
List<BindingSet> bindings) |
protected static String |
constructJoinArg(ExclusiveTupleExpr exclusiveExpr,
Set<String> varNames,
BindingSet bindings)
Construct a query substring from the
ExclusiveTupleExpr that can be used as an argument to a
Join . |
protected static String |
constructStatement(StatementPattern stmt,
Set<String> varNames,
BindingSet bindings)
Construct the statement string, i.e.
|
protected static String |
constructStatementCheckId(StatementPattern stmt,
int varID,
Set<String> varNames,
BindingSet bindings)
Construct the statement string, i.e.
|
protected static String |
constructStatementId(StatementPattern stmt,
String varID,
Set<String> varNames,
BindingSet bindings)
Construct the statement string, i.e.
|
protected static String |
getValueString(Value value)
Return the string representation of this value, see
appendValue(StringBuilder, Value) for details. |
static boolean |
hasFreeVars(StatementPattern stmt,
BindingSet bindings)
returns true iff there is at least one free variable, i.e.
|
static List<String> |
loadQueries(String queryFile)
load the queries from a queries file located at the specified path.
|
static String |
selectQueryString(ExclusiveGroup group,
BindingSet bindings,
FilterValueExpr filterExpr,
AtomicBoolean evaluated,
Dataset dataset)
Construct a SELECT query for the provided
ExclusiveGroup . |
static String |
selectQueryString(ExclusiveTupleExprRenderer expr,
BindingSet bindings,
FilterValueExpr filterExpr,
AtomicBoolean evaluated,
Dataset dataset)
Construct a SELECT query for the provided
ExclusiveTupleExprRenderer |
static String |
selectQueryString(StatementPattern stmt,
BindingSet bindings,
FilterValueExpr filterExpr,
AtomicBoolean evaluated,
Dataset dataset)
Construct a SELECT query for the provided statement.
|
static String |
selectQueryStringBoundCheck(StatementPattern stmt,
List<BindingSet> unionBindings,
Dataset dataset)
Construct a SELECT query for a grouped bound check.
|
static String |
selectQueryStringBoundJoinVALUES(StatementPattern stmt,
List<BindingSet> unionBindings,
FilterValueExpr filterExpr,
AtomicBoolean evaluated,
Dataset dataset)
Creates a bound join subquery using the SPARQL 1.1 VALUES operator.
|
static String |
selectQueryStringBoundUnion(StatementPattern stmt,
List<BindingSet> unionBindings,
FilterValueExpr filterExpr,
Boolean evaluated,
Dataset dataset)
Deprecated.
replaced with
#selectQueryStringBoundJoinVALUES(StatementPattern, List, FilterValueExpr, AtomicBoolean) |
static String |
selectQueryStringLimit1(ExclusiveGroup group,
BindingSet bindings,
Dataset dataset)
Construct a SELECT query for the provided
ExclusiveGroup with LIMIT 1. |
static String |
selectQueryStringLimit1(ExclusiveTupleExpr expr,
BindingSet bindings,
Dataset dataset)
Construct a SELECT query for the provided expr with LIMIT 1.
|
static String |
selectQueryStringLimit1(StatementPattern stmt,
BindingSet bindings,
Dataset dataset)
Construct a SELECT query for the provided statement with LIMIT 1.
|
static String |
toString(ArbitraryLengthPath node,
Set<String> varNames,
BindingSet bindings)
Converts an
ArbitraryLengthPath node to a sub query string and makes sure to insert any bindings. |
static String |
toString(Resource subj,
IRI pred,
Value obj)
Return a string representation of this statement using the following pattern, where variables are indicated using
?var and values are represented as strings.
|
static String |
toString(StatementPattern stmt)
Return a string representation of this statement using the following pattern, where variables are indicated using
?var and values are represented as strings.
|
static String |
toString(Var var) |
public static final IRI BNODE_URI
BNode
s in appendBNode(StringBuilder, BNode)
since
BNodes cannot be expressed in SPARQL queriespublic static boolean hasFreeVars(StatementPattern stmt, BindingSet bindings)
stmt
- bindings
- public static String toString(StatementPattern stmt)
stmt
- public static String toString(ArbitraryLengthPath node, Set<String> varNames, BindingSet bindings)
ArbitraryLengthPath
node to a sub query string and makes sure to insert any bindings.
This method assumes that the ArbitraryLengthPath.getPathExpression()
is a StatementPattern
.
node
- varNames
- bindings
- public static String toString(Resource subj, IRI pred, Value obj)
subj
- the subjectpred
- the predicateobj
- the objectpublic static String selectQueryString(StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated, Dataset dataset) throws IllegalQueryException
stmt
- bindings
- filterExpr
- evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in
beginningIllegalQueryException
- if the query does not have any free variablespublic static String selectQueryString(ExclusiveTupleExprRenderer expr, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated, Dataset dataset) throws IllegalQueryException
ExclusiveTupleExprRenderer
stmt
- bindings
- filterExpr
- evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in
beginningIllegalQueryException
- if the query does not have any free variablespublic static String selectQueryString(ExclusiveGroup group, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated, Dataset dataset) throws IllegalQueryException
ExclusiveGroup
. Note that bindings and filterExpr are applied
whenever possible.group
- the expression for the querybindings
- the bindings to be appliedfilterExpr
- a filter expression or nullevaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in
beginningIllegalQueryException
public static String askQueryString(ExclusiveTupleExpr expr, BindingSet bindings, Dataset dataset)
ExclusiveTupleExpr
into a ASK query stringexpr
- bindings
- IllegalQueryException
@Deprecated public static String selectQueryStringBoundUnion(StatementPattern stmt, List<BindingSet> unionBindings, FilterValueExpr filterExpr, Boolean evaluated, Dataset dataset)
#selectQueryStringBoundJoinVALUES(StatementPattern, List, FilterValueExpr, AtomicBoolean)
stmt
- unionBindings
- filterExpr
- evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false
in beginningpublic static String selectQueryStringBoundJoinVALUES(StatementPattern stmt, List<BindingSet> unionBindings, FilterValueExpr filterExpr, AtomicBoolean evaluated, Dataset dataset)
Example subquery:
SELECT ?v ?__index WHERE { VALUES (?s ?__index) { (:s1 1) (:s2 2) ... (:sN N) } ?s name ?v. }
stmt
- unionBindings
- filterExpr
- evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false
in beginningSparqlFederationEvalStrategy
,
BoundJoinVALUESConversionIteration
public static String selectQueryStringBoundCheck(StatementPattern stmt, List<BindingSet> unionBindings, Dataset dataset)
stmt
- unionBindings
- protected static String constructInnerUnion(StatementPattern stmt, int outerID, Set<String> varNames, List<BindingSet> bindings)
protected static String constructJoinArg(ExclusiveTupleExpr exclusiveExpr, Set<String> varNames, BindingSet bindings)
ExclusiveTupleExpr
that can be used as an argument to a
Join
.
This method can only be used for ExclusiveTupleExpr
that additionally provide
ExclusiveTupleExprRenderer
capabilities. An exception to this is if the given expression is a
StatementPattern
, e.g. an ExclusiveStatement
or ExclusiveGroup
.
exclusiveExpr
- varNames
- bindings
- public static String askQueryString(StatementPattern stmt, BindingSet bindings, Dataset dataset)
stmt
- bindings
- public static String selectQueryStringLimit1(StatementPattern stmt, BindingSet bindings, Dataset dataset)
stmt
- bindings
- public static String selectQueryStringLimit1(ExclusiveTupleExpr expr, BindingSet bindings, Dataset dataset)
stmt
- bindings
- public static String selectQueryStringLimit1(ExclusiveGroup group, BindingSet bindings, Dataset dataset)
ExclusiveGroup
with LIMIT 1. Such query can be used for source
selection instead of ASK queries.group
- bindings
- protected static String constructStatement(StatementPattern stmt, Set<String> varNames, BindingSet bindings)
stmt
- varNames
- bindings
- protected static String constructStatementId(StatementPattern stmt, String varID, Set<String> varNames, BindingSet bindings)
stmt
- varNames
- bindings
- protected static String constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings)
stmt
- varID
- varNames
- bindings
- protected static StringBuilder appendVar(StringBuilder sb, Var var, Set<String> varNames, BindingSet bindings)
sb
- var
- varNames
- bindings
- protected static StringBuilder appendVarId(StringBuilder sb, Var var, String varID, Set<String> varNames, BindingSet bindings)
sb
- var
- varNames
- bindings
- protected static String getValueString(Value value)
appendValue(StringBuilder, Value)
for details.value
- protected static StringBuilder appendValue(StringBuilder sb, Value value)
sb
- value
- protected static StringBuilder appendURI(StringBuilder sb, IRI uri)
sb
- uri
- protected static StringBuilder appendBNode(StringBuilder sb, BNode bNode)
BNODE_URI
) to represent the BNode.
Note: currently it is not possible to retrieve values for a BNode via SPARQL, hence we use a dummy BNode which
does not produce any results. A warning is printed to debug.sb
- bNode
- protected static StringBuilder appendLiteral(StringBuilder sb, Literal lit)
sb
- lit
- public static List<String> loadQueries(String queryFile) throws FileNotFoundException, IOException
queryFile
- FileNotFoundException
IOException
Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.