Abstract Algebra Expressions

Dydra accepts query requests in the form of abstract algebra expressions in addition to SPARQL texts. These express each operation as an s-expression, in which the operator is present in the first position and any arguments occupy successive positions.

In the case of a simple query such as

SELECT ?s ?p ?o WHERE { ?s ?p ?o }

the equivalent algebra expression would be

(select
   (bgp
     (triple ?:s ?:p ?:o))
   (?:s ?:p ?:o))

day (ARG)

FUNCTION ( (or DATE DATE-TIME DAY-TIME-DURATION G-DAY G-MONTH-DAY) ) T

The function DAY returns the day part of arg as an integer. This function corresponds to fn:day-from-dateTime and its variations.

hours (ARG)

FUNCTION ( (or DATE-TIME DAY-TIME-DURATION TIME) ) T

The function HOURS returns the hours part of arg as an integer. The value is as given in the lexical form of the XSD dateTime. This function corresponds to fn:hours-from-dateTime.

minutes (ARG)

FUNCTION ( (or DATE-TIME DAY-TIME-DURATION TIME) ) T

The function MINUTES returns the minutes part of the lexical form of arg. The value is as given in the lexical form of the XSD dateTime. This function corresponds to fn:minutes-from-dateTime.

month (ARG)

FUNCTION ( (or DATE DATE-TIME YEAR-MONTH-DURATION G-MONTH G-MONTH-DAY G-YEAR-MONTH) ) T

The function MONTH returns the month part of arg as an integer. This function corresponds to fn:month-from-dateTime.

seconds (ARG)

FUNCTION ( (or date-time day-time-duration time) ) t

the function seconds returns the seconds part of the lexical form of arg. This function corresponds to fn:seconds-from-datetime.

tz (ARG)

FUNCTION ( ( xsd:dateTime ) simpleLiteral )

The function TZ returns the timezone part of arg as an xsd:dayTimeDuration. Raises an error if there is no timezone. This function corresponds to fn:timezone-from-dateTime except for the treatment of literals with no timezone. As all times are recorded as zulu times, the function constantly returns ‘Z’

year (ARG)

FUNCTION ( (or DATE DATE-TIME YEAR-MONTH-DURATION G-YEAR G-YEAR-MONTH) ) T

The function YEAR returns the year part of arg as an integer.

This function corresponds to fn:year-from-dateTime.

! (EXPRESSION)

MACRO

!= (TERM1 TERM2)

MACRO

&& (&OPTIONAL TERM1 TERM2 &REST OTHER-TERMS)

MACRO ( xsd:boolean )

The && operator returns a logical AND of left and right. Note that logical-and operates on the effective boolean value of its arguments.

XQuery defines that an IF form need not evaluate an unselected alternative. It says nothing about the semantics for logical operators. This implementation handles the two expresions the same.

* (EXPRESSION-1 EXPRESSION-2)

MACRO

+ (EXPRESSION-1 &OPTIONAL EXPRESSION-2)

MACRO

- (EXPRESSION-1 &OPTIONAL EXPRESSION-2)

MACRO

/ (EXPRESSION-1 EXPRESSION-2)

MACRO

< (ARG1 ARG2)

MACRO ( ( numeric numeric ) xsd:boolean)

The function ‘<’ compares the two arguments and returns true iff arg1 is strictly less than arg2. The implemented comparison is contingent upon whether it can be determined that the arguments are constants, and then if so, strings with language tages. In that case delegate to the store’s operator for collation-sequence dependent order. In other cases, retrieve the terms and then continue with those values as arguments.

<= (EXPRESSION-1 EXPRESSION-2)

MACRO ( ( numeric numeric ) xsd:boolean)

The function ‘<’ compares the two arguments and returns true iff arg1 is less or equal to arg2. The implemented comparison is comparison contingent upon whether it can be determined that the arguments are constants, and then if so, strings with language tages. In that case delegate to the store’s operator for collation-sequence dependent order. In other cases, instantiate the terms and then continue with those values as arguments.

= (TERM1 TERM2)

MACRO ( xsd:boolean )

The = operator 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: - 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].

> (EXPRESSION-1 EXPRESSION-2)

MACRO

>= (EXPRESSION-1 EXPRESSION-2)

MACRO

abs (TERM)

MACRO ( ( numeric ) numeric )

The function ABS returns the absolute value of arg. An error is raised if arg is not a numeric value.

This function is the same as fn:numeric-abs for terms with a datatype from XDM.

add (FROM-GRAPH TO-GRAPH &KEY VERBOSE)

MACRO

aggregate (SOLUTION-FIELD BINDINGS &REST ARGS &KEY COUNT END LIMIT OFFSET START)

MACRO

ask (EXPRESSION)

MACRO ( ( solutionField ) xsd:boolean )

The ASK form yields true iff the solution field is not empty. No information is returned about the possible query solutions, just whether or not a solution exists.

bgp (&BODY BODY)

MACRO

bindings (SOLUTIONS VARIABLES)

MACRO ( ( solutionSequence variable* ) solutionField )

A BINDINGS form combines a sequence of solutions vith variables as dimensions to produce an unordered solution field, which can be serve as an argument to other query forms. There solution sequence may comprise constant values only.

bnode (&OPTIONAL LITERAL)

MACRO ( ( literal? ) blankNode )

The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions. If the no argument form is used, every call results in a distinct blank node. If the form with a simple literal is used, every call results in distinct blank nodes for different simple literals, and the same blank node for calls with the same simple literal within expressions for one solution mapping.

bound (VAR)

MACRO ( ( RDFTerm ) xsd:boolean )

The function BOUND returns true if var is bound to a value. Returns false otherwise. Variables with the value NaN or INF are considered bound. If there is no lexical definition, the result is constantly false.

ceil (TERM)

MACRO ( ( numeric ) numeric )

The function CEIL returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of arg. An error is raised if arg is not a numeric value.

This function is the same as fn:numeric-ceil for terms with a datatype from XDM.

clear (GRAPH &KEY VERBOSE)

MACRO

concat (&REST LITERALS)

MACRO ( ( stringLiteral* ) stringLiteral )

The CONCAT function corresponds to the XPath fn:concat function. The function accepts string literals as arguments.

The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs. If all input literals are typed literals of type xsd:string, then the returned literal is also of type xsd:string, if all input literals are plain literals with identical language tag, then the returned literal is a plain literal with the same language tag, in all other cases, the returned literal is a simple literal.

construct (SOLUTION-FIELD GRAPH-PATTERN)

MACRO ( ( solutionField pattern ) RDFSolutionField )

A CONSTRUCT form applies the given graph-pattern template to each solution of the given solution-field to produce a field which denotes the projected RDF graph.

contains (ARG1 ARG2)

MACRO

copy (FROM-GRAPH TO-GRAPH &KEY VERBOSE)

MACRO

count (SUBJECT PREDICATE OBJECT &OPTIONAL GRAPH)

MACRO

create (GRAPH &KEY VERBOSE)

MACRO

datatype (LITERAL)

MACRO ( ( literal ) iri )

Returns the datatype IRI of a literal. - If the literal is a typed literal, return the datatype IRI. - If the literal is a simple literal, return xsd:string - If the literal is literal with a language tag, return rdf:langString

deleteData (QUAD-OR-TRIPLE-DATA)

MACRO

deleteWhere (QUAD-PATTERN)

MACRO

describe (SOLUTION-FIELD &OPTIONAL SUBJECTS)

MACRO ( ( solutionField anyURI* ) RDFSolutionField )

A DESCRIBE form merges all resource IRI from the given solution-field and subject resource list, performs iteratve queries to produce the bounded descriptions for those resources and yields an RDF graph which enumerates their relations in the store.

The extent is governed by configuration parameters: - <urn:dydra:describeForm> - <urn:dydra:describeSubjectDepth> - <urn:dydra:describeObjectDepth>

diff (SOLUTION-FIELD1 SOLUTION-FIELD2 &REST ARGS &KEY COUNT END OFFSET START TEST)

MACRO ( ( solutionField solutionField ) solutionField )

A DIFF form combines two solution fields with an optional predicate to be applied to each compatible, merged solution. The result is those solutions from the first field which are either incompatible with all solutions in the second field, or fail the predicate when combined with compatible solutions.

distinct (&WHOLE FORM SOLUTION-FIELD &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField ) solutionField )

A DISTINCT form accepts a single solution field and yields an analogous field which removes the duplicate solutions.

drop (GRAPH &KEY VERBOSE)

MACRO

encode_for_uri (LITERAL)

MACRO

exists (PATTERN)

MACRO ( xsd:boolean )

The filter operator EXISTS that takes a graph pattern and returns true/false depending on whether the pattern matches the dataset given the bindings in the current group graph pattern, the dataset and the active graph at this point in the query evaluation. No additional binding of variables occurs.

The NOT EXISTS form translates into fn:not(EXISTS{…}).

exprlist (&REST EXPRESSIONS)

MACRO

extend (FIELD-EXPRESSION VARIABLE VALUE-EXPRESSION &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField variable RDFTerm ) solutionField )

An EXTEND form extends each solution in its solution-field argument with an additional dimension in which the given variable is bound to the respective result of evaluating the given expression for each solution. If the evaluation fails, the variable remains unbound.

filter (&WHOLE FORM SOLUTION-FIELD TEST-EXPRESSION &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField (function (solution) xsd:boolean) ) solutionField )

A FILTER form applies a predicate function to each solution in a given field to generate a new solution field which includes only those input solutions which satisfy the predicate.

Where possible, the evaluation process folds any constant values into the argument patterns and pushes predicate to limit the matching and combination processing in the constitutent solution field.

floor (TERM)

MACRO ( ( numeric ) numeric )

The function FLOOR returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of arg. An error is raised if arg is not a numeric value.

This function is the same as fn:numeric-floor for terms with a datatype from XDM.

graph (NAME GROUP-GRAPH-PATTERN)

MACRO ( ( (or anyURI variable) graphPattern ) solutionField )

A GRAPH form modifies the application of a basic group graph pattern to either - constrain its extent to the specific graph named by the constant IRI, or - limit its domain to those named graphs enumerated in the dataset definition, or - permit it to range over all named graphs. In the latter two cases, the result solution field will include a binding for the respective graph in each solution.

group (SOLUTION-FIELD KEY-BINDINGS &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField ( variable (function (solution) RDFTerm) )* ) ( RDFTerm solutionField )* )

A GROUP form extends a given solution field with keys which are composed of set of computed bindings and then segments the field according to those keys.

if (PREDICATE CONSEQUENT ALTERNATIVE)

MACRO ( rdfTerm )

The IF form evaluates the first argument, interprets it as a effective boolean value, then returns the value of consequent if the EBV is true, otherwise it returns the value of alternative. Only one of consequent and alternative is evaluated. If evaluating the predicate expression raises an error, then an error is raised for the evaluation of the IF expression.

in (EXPRESSION EXPRESSION-LIST)

MACRO

insertData (QUAD-OR-TRIPLE-DATA)

MACRO

iri (EXPRESSION)

MACRO ( ( RDFTerm ) iri)

The IRI function constructs an IRI by resolving the string argument (see RFC 3986 and RFC 3987 or any later RFC that superceeds RFC 3986 or RFC 3987). The IRI is resolved against the base IRI of the query and must result in an absolute IRI. The URI function is a synonym for IRI. If the function is passed an IRI, it returns the IRI unchanged. Passing any RDF term other than a simple literal, xsd:string or an IRI is an error. An implementation may normalize the IRI.

isBlank (EXPRESSION)

MACRO ( ( RDFTerm ) xsd:boolean )

Returns true if expression yields a blank node. Returns false otherwise.

isIRI (EXPRESSION)

MACRO ( ( RDFTerm ) xsd:boolean )

Returns true if term is an IRI. Returns false otherwise.

isLiteral (EXPRESSION)

MACRO ( ( RDFTerm ) xsd:boolean )

Returns true if expression yields a literal. Returns false otherwise.

isURI (EXPRESSION)

MACRO ( ( RDFTerm ) xsd:boolean )

isURI is an alternate spelling for the isIRI operator.

join (&WHOLE FORM FIELD1 FIELD2 &REST ARGS &KEY COUNT END OFFSET START TEST)

MACRO ( ( solutionField solutionField (function (solution) xsd:boolean)? ) solutionField )

A JOIN form combines two solution fields and yields a new field in which each solution is either a merge of two compatible solutions from the constituent fields, in the case where a natural join is possible, or an element of the cross join of the two fields, in the case where no dimension agrees.

Where a test predicate is given, all result solutions satisfy it.

lang (LITERAL)

MACRO ( ( literal ) simpleLiteral )

Returns the language tag of literal, if it has one. It returns ‘’ if literal has no language tag. Note that the RDF data model does not include literals with an empty language tag.

langMatches (LANGUAGE-TAG LANGUAGE-RANGE)

MACRO ( ( simpleLiteral simpleLiteral ) xsd:boolean )

The function LANGMATCHES Returns true if language-tag (first argument) matches language-range (second argument) per the basic filtering scheme defined in [RFC4647] section 3.3.1. language-range is a basic language range per Matching of Language Tags [RFC4647] section 2.1. A language-range of

lcase (STR)

MACRO

leftjoin (&WHOLE FORM SOLUTION-FIELD1 SOLUTION-FIELD2 &REST ARGS &KEY TEST COUNT END OFFSET START)

MACRO ( ( solutionField solutionField (function (solution) xsd:boolean)? ) solutionField )

A LEFTJOIN form combines two solution fields and yields a new field in which each solution is either a merge of two compatible solutions from the constituent fields or a solution from the first field, in the case where a natural join is possible, or an element of the cross join of the two fields, in the case where no dimension agrees.

Where a test predicate is given, all result solutions satisfy it.

list (&REST ARGS)

MACRO

load (FROM-LOCATION GRAPH-DESIGNATOR &REST ARGS &KEY VERBOSE)

MACRO

max (EXPRESSION1 EXPRESSION2)

MACRO

md5 (ARG)

MACRO

min (EXPRESSION1 EXPRESSION2)

MACRO

minus (SOLUTION-FIELD1 SOLUTION-FIELD2 &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField solutionField ) solutionField )

A MINUS form combines two solution fields to produce a result field which contains all solutions from the first field for which no compatible solution is present in the second field.

modify (FIELD-EXPRESSION &REST ARGS &KEY DELETE INSERT WITH GRAPHS NAMED-GRAPHS)

MACRO

move (FROM-GRAPH TO-GRAPH &KEY VERBOSE)

MACRO

notin (EXPRESSION EXPRESSION-LIST)

MACRO

now NIL

MACRO ( () xsd:dateTime )

The function NOW returns an XSD dateTime value for the current query execution. All calls to this function in any one query execution must return the same value. The moment is that recorded when the query process was created.

null (&OPTIONAL DIMENSIONS)

MACRO ( ( variable*? ) solutionField )

A NULL form produces an empty solution field of the given dimensionality

order (SOLUTION-FIELD ORDER-PREDICATE-FORM)

MACRO ( ( solutionField (function (solution solution) xsd:boolean) ) solutionField )

A SORT form applies an ordering predicate to a given solution field to produce a result filed in which each successive solution pair satisfies the given predicate.

project (SOLUTION-FIELD RESULT-DIMENSIONS &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField ) solutionField )

A PROJECT form produces a new solution field in which each solution comprises just the specified elements. Each element can be either a variable, or a (variable expression) binding. In the first case, any supplied argument value is included in the result solution. In the second, the respective expression for is evaluated for each solution to produce the respective result. If the variable is not bound in the original solution, no value appears in the result.

quad (SUBJECT PREDICATE OBJECT GRAPH)

MACRO

rand NIL

MACRO ( () xsd:double )

The function RAND returns a pseudo-random number between 0 (inclusive) and 1.0e0 (exclusive). Different numbers can be produced every time this function is invoked. Numbers should be produced with approximately equal probability.

reduced (SOLUTION-FIELD &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField ) solutionField )

A REDUCED form accepts a single solution field and yields an analogous field which removes the duplicate solutions.

regex (TEXT PATTERN &OPTIONAL (FLAGS NIL))

MACRO ( ( stringLiteral simpleLiteral simpleLiteral? ) xsd:boolean )

The REGEX function invokes the XPath fn:matches function to match text against a regular expression pattern. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section 7.6.1 Regular Expression Syntax.

If the pattern is a constant, precompile it.

replace (ARG PATTERN REPLACEMENT &OPTIONAL (FLAGS NIL))

MACRO ( ( stringLiteral simpleLiteral simpleLiteral simpleLiteral? ) stringLiteral )

The REPLACE function corresponds to the XPath fn:replace function. It replaces each non-overlapping occurrence of the regular expression pattern with the replacement string. Regular expession matching may involve modifier flags. See REGEX.

If the pattern is a constant, preprocess it.

round (TERM)

MACRO ( ( numeric ) numeric )

The function ROUND returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if arg is not a numeric value.

This function is the same as fn:numeric-round for terms with a datatype from XDM.

sameTerm (TERM1 TERM2)

MACRO ( (rdfTerm rdfTerm) xsd:boolean )

The function SAMETERM returns TRUE if term1 and term2 are the same RDF term as defined in Resource Description Framework (RDF): Concepts and Abstract Syntax [CONCEPTS]; returns FALSE otherwise.

select (&WHOLE FORM EXPRESSION SELECTION-SPECIFICATION &REST ARGS &KEY COUNT END OFFSET START)

MACRO

service (IRI GROUP-GRAPH-PATTERN &REST ARGS &KEY SILENT QUERY-TEXT)

MACRO

sha1 (ARG)

MACRO

sha224 (ARG)

MACRO

sha256 (ARG)

MACRO

sha384 (ARG)

MACRO

sha512 (ARG)

MACRO

slice (SOLUTION-FIELD &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField ) solutionField )

A SLICE form reduces a given solution field to produce a result field which includes only those solutions within the specified [offset end) interval.

str (EXPRESSION)

MACRO

strafter (ARG1 ARG2)

MACRO

strbefore (ARG1 ARG2)

MACRO

strdt (LEXICALFORM IRI)

MACRO ( (simpleLiteral IRI) literal )

The STRDT function constructs a literal with lexical form and type as specified by the arguments.

strends (ARG1 ARG2)

MACRO

strlang (EXPRESSION1 EXPRESSION2)

MACRO ( ( simpleLiteral simpleLiteral) literal )

The STRLANG function constructs a literal with lexical form and language tag as specified by the arguments.

strlen (TERM)

MACRO

strstarts (ARG1 ARG2)

MACRO

struuid NIL

MACRO ( () simpleLiteral )

Return a string that is the scheme specific part of UUID. That is, as a simple literal, the result of generating a UUID, converting to a simple literal and removing the initial urn:uuid:.

substr (LITERAL STARTINGLOC &OPTIONAL LENGTH)

MACRO ( ( stringLiteral xsd:integer ) stringLiteral )

The SUBSTR function corresponds to the XPath fn:substring function and returns a literal of the same kind (simple literal, literal with language tag, xsd:string typed literal) as the source input parameter but with a lexical form formed from the substring of the lexical form of the source.

The arguments startingLoc and length may be derived types of xsd:integer.

The index of the first character in a strings is 1.

table (&OPTIONAL DIMENSIONS &KEY GRAPH)

MACRO ( ( variable*? ) solutionField )

A TABLE form produces an zero-dimension solution field with a single solution. If in the scope of a GRAPH form, a constant graph name will reduce the result to a null field if the graph does not exist.

Per rec-sparql[1], the ‘unit’ table is ‘one solution that does not bind any variables.’ — [1]: http://www.w3.org/TR/rdf-sparql-query/#emptyGroupPattern

timezone (ARG)

MACRO ( ( xsd:dateTime ) xsd:dayTimeDuration )

The function TIMEZONE returns the timezone part of arg as an xsd:dayTimeDuration. Raises an error if there is no timezone. This function corresponds to fn:timezone-from-dateTime except for the treatment of literals with no timezone. As all values are represented as zulu times, the function constantly returns ‘PT0S’^^xsd:dayTimeDuration.

triple (SUBJECT PREDICATE OBJECT)

MACRO

ucase (STR)

MACRO

union (SOLUTION-FIELD1 SOLUTION-FIELD2 &REST ARGS &KEY COUNT END OFFSET START)

MACRO ( ( solutionField solutionField ) solutionField )

A UNION form combines to solution fields to produce a result field which contains all solutions from the first field followed by those in the second.

update (&REST OPERATIONS)

MACRO

uri (EXPRESSION)

MACRO ( ( RDFTerm ) iri)

The URI function is a synonym for IRI.

uuid NIL

MACRO ( () iri )

The UUID function return a fresh IRI from the UUID URN scheme. Each call of UUID() returns a different UUID. It must not be the

|| (LEFT RIGHT)

MACRO ( xsd:boolean )

The || operator returns a logical OR of left and right. Note that logical-or operates on the effective boolean value of its arguments.

XQuery defines that an IF form need not evaluate an unselected alternative. It says nothing about the semantics for logical operators. This implementation handles the two expresions the same.