Class QueryEvaluationUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ValueExprEvaluationException
static final ValueExprEvaluationException
static final ValueExprEvaluationException
static final ValueExprEvaluationException
static final ValueExprEvaluationException
static final ValueExprEvaluationException
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
compare
(Value leftVal, Value rightVal, Compare.CompareOp operator) static boolean
compare
(Value leftVal, Value rightVal, Compare.CompareOp operator, boolean strict) static boolean
compareLiterals
(Literal leftLit, Literal rightLit, Compare.CompareOp operator) Compares the suppliedLiteral
arguments using the supplied operator, using strict (minimally-conforming) SPARQL 1.1 operator behavior.static boolean
compareLiterals
(Literal leftLit, Literal rightLit, Compare.CompareOp operator, boolean strict) Compares the suppliedLiteral
arguments using the supplied operator.private static boolean
compareWithOperator
(Compare.CompareOp operator, int i) static boolean
compatibleArguments
(Literal arg1, Literal arg2) Checks whether the supplied two literal arguments are 'argument compatible' according to the SPARQL definition.private static CoreDatatype.XSD
getCommonDatatype
(boolean strict, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype) static boolean
getEffectiveBooleanValue
(Value value) Determines the effective boolean value (EBV) of the supplied value as defined in the SPARQL specification: The EBV of any literal whose type is CoreDatatype.XSD:boolean or numeric is false if the lexical form is not valid for that datatype (e.g.static boolean
static boolean
Checks whether the supplied value is a "plain literal".static boolean
isSimpleLiteral
(boolean isLang, CoreDatatype datatype) Checks whether the supplied literal is a "simple literal".static boolean
Checks whether the supplied literal is a "simple literal".static boolean
Checks whether the supplied value is a "simple literal".static boolean
Checks whether the supplied literal is a "string literal".static boolean
Checks whether the supplied literal is a "string literal".private static boolean
isSupportedDatatype
(CoreDatatype.XSD datatype) private static boolean
otherCases
(Literal leftLit, Literal rightLit, Compare.CompareOp operator, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype, boolean leftLangLit, boolean rightLangLit, boolean strict) private static void
validateDatatypeCompatibility
(boolean strict, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype) Validate if we are comparing supported but incompatible datatypes.
-
Field Details
-
INDETERMINATE_DATE_TIME_EXCEPTION
-
STRING_WITH_OTHER_SUPPORTED_TYPE_EXCEPTION
-
NUMERIC_WITH_OTHER_SUPPORTED_TYPE_EXCEPTION
-
DATE_WITH_OTHER_SUPPORTED_TYPE_EXCEPTION
-
UNSUPPOERTED_TYPES_EXCEPTION
-
NOT_COMPATIBLE_AND_ORDERED_EXCEPTION
-
-
Constructor Details
-
QueryEvaluationUtil
public QueryEvaluationUtil()
-
-
Method Details
-
getEffectiveBooleanValue
Determines the effective boolean value (EBV) of the supplied value as defined in the SPARQL specification:- The EBV of any literal whose type is CoreDatatype.XSD:boolean or numeric is false if the lexical form is not valid for that datatype (e.g. "abc"^^xsd:integer).
- If the argument is a typed literal with a datatype of CoreDatatype.XSD:boolean, the EBV is the value of that argument.
- If the argument is a plain literal or a typed literal with a datatype of CoreDatatype.XSD:string, the EBV is false if the operand value has zero length; otherwise the EBV is true.
- If the argument is a numeric type or a typed literal with a datatype derived from a numeric type, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.
- All other arguments, including unbound arguments, produce a type error.
- Parameters:
value
- Some value.- Returns:
- The EBV of value.
- Throws:
ValueExprEvaluationException
- In case the application of the EBV algorithm results in a type error.
-
compare
public static boolean compare(Value leftVal, Value rightVal, Compare.CompareOp operator) throws ValueExprEvaluationException - Throws:
ValueExprEvaluationException
-
compare
public static boolean compare(Value leftVal, Value rightVal, Compare.CompareOp operator, boolean strict) throws ValueExprEvaluationException - Throws:
ValueExprEvaluationException
-
compareLiterals
public static boolean compareLiterals(Literal leftLit, Literal rightLit, Compare.CompareOp operator) throws ValueExprEvaluationException Compares the suppliedLiteral
arguments using the supplied operator, using strict (minimally-conforming) SPARQL 1.1 operator behavior.- Parameters:
leftLit
- the left literal argument of the comparison.rightLit
- the right literal argument of the comparison.operator
- the comparison operator to use.- Returns:
true
if execution of the supplied operator on the supplied arguments succeeds,false
otherwise.- Throws:
ValueExprEvaluationException
- if a type error occurred.
-
compareLiterals
public static boolean compareLiterals(Literal leftLit, Literal rightLit, Compare.CompareOp operator, boolean strict) throws ValueExprEvaluationException Compares the suppliedLiteral
arguments using the supplied operator.- Parameters:
leftLit
- the left literal argument of the comparison.rightLit
- the right literal argument of the comparison.operator
- the comparison operator to use.strict
- boolean indicating whether comparison should use strict (minimally-conforming) SPARQL 1.1 operator behavior, or extended behavior.- Returns:
true
if execution of the supplied operator on the supplied arguments succeeds,false
otherwise.- Throws:
ValueExprEvaluationException
- if a type error occurred.
-
otherCases
private static boolean otherCases(Literal leftLit, Literal rightLit, Compare.CompareOp operator, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype, boolean leftLangLit, boolean rightLangLit, boolean strict) -
validateDatatypeCompatibility
private static void validateDatatypeCompatibility(boolean strict, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype) throws ValueExprEvaluationException Validate if we are comparing supported but incompatible datatypes. Throws aValueExprEvaluationException
if this is the case.Used in a strict / minimally-conforming interpretation of the SPARQL specification. In the SPARQL 1.1 operator mapping table, when comparing two literals with different datatypes (that cannot be cast to a common type), the only mapping that applies is comparison using RDF term-equality:
A != B RDF term RDF term fn:not(RDFterm-equal(A, B)) xsd:boolean Returns TRUE if term1 and term2 are the same RDF term as defined in Resource Description Framework (RDF): Concepts and Abstract Syntax [CONCEPTS]; produces a type error if the arguments are both literal but are not the same RDF term; returns FALSE otherwise. term1 and term2 are the same if any of the following is true:
(emphasis ours)- term1 and term2 are equivalent IRIs as defined in 6.4 RDF URI References of [CONCEPTS].
- term1 and term2 are equivalent literals as defined in 6.5.1 Literal Equality of [CONCEPTS].
- term1 and term2 are the same blank node as described in 6.6 Blank Nodes of [CONCEPTS].
When applying the SPARQL specification in a minimally-conforming manner, RDFterm-equal is supposed to return a type error whenever we compare two literals with incompatible datatypes: we have two literals, but they are not the same RDF term (as they are not equivalent literals as defined in the linked section in RDF Concepts). This holds even if those two datatypes that fully supported and understood (say, when comparing an xsd:string and an xsd:boolean).
In a non-strict interpretation, however, we allow comparing comparing two literals with incompatible but supported datatypes (string, numeric, calendar): An equality comparison will result in
false
, and an inequality comparison will result intrue
. Note that this does not violate the SPARQL specification as it falls under operator extensibility (section 17.3.1).- Parameters:
strict
- flag indicating if query evaluation is operating in strict/minimally-conforming mode.leftCoreDatatype
- the left datatype to comparerightCoreDatatype
- the right datatype to compare- Throws:
ValueExprEvaluationException
- if query evaluation is operating in strict mode, and the two supplied datatypes are both supported datatypes but not comparable.- See Also:
-
getCommonDatatype
private static CoreDatatype.XSD getCommonDatatype(boolean strict, CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype) -
compareWithOperator
-
isPlainLiteral
Checks whether the supplied value is a "plain literal". A "plain literal" is a literal with no datatype and optionally a language tag.- See Also:
-
isPlainLiteral
-
isSimpleLiteral
Checks whether the supplied value is a "simple literal". A "simple literal" is a literal with no language tag nor datatype.- See Also:
-
isSimpleLiteral
Checks whether the supplied literal is a "simple literal". A "simple literal" is a literal with no language tag and the datatypeCoreDatatype.XSD.STRING
.- See Also:
-
isSimpleLiteral
Checks whether the supplied literal is a "simple literal". A "simple literal" is a literal with no language tag and the datatypeCoreDatatype.XSD.STRING
.- See Also:
-
isStringLiteral
Checks whether the supplied literal is a "string literal". A "string literal" is either a simple literal, a plain literal with language tag, or a literal with datatype CoreDatatype.XSD:string.- See Also:
-
compatibleArguments
Checks whether the supplied two literal arguments are 'argument compatible' according to the SPARQL definition.- Parameters:
arg1
- the first argumentarg2
- the second argument- Returns:
- true iff the two supplied arguments are argument compatible, false otherwise
- See Also:
-
isStringLiteral
Checks whether the supplied literal is a "string literal". A "string literal" is either a simple literal, a plain literal with language tag, or a literal with datatype CoreDatatype.XSD:string.- See Also:
-
isSupportedDatatype
-