Functions in ARQ

SPARQL allows custom functions in filter expressions so that queries can be used on domain-specific data. SPARQL defines a function by URI (or qname) in FILTER expressions.  ARQ provides a function library and supports application-provided functions.  There is a mechanism for dynamically loading.

Function Library

RDF Graph Functions

Function name Description
jfn:listMember(list, resource) Test whether a resource is a member of an RDF collection (AKA list)
jfn:listIndex(list, resource) Return the index of the resource in the RDF collection. Cause an evaluation exception if not a member (and so the expression will not pass the filter unless inside a value disjunction).
jfn:bagMember(bag, resource) Test whether a resource is a member of an RDF bag
jfn:seqMember(bag, resource) Test whether a resource is a member of an RDF seq
jfn:altMember(bag, resource) Test whether a resource is a member of an RDF alt
jfn:langeq(literal, lang) Compare the language tag of the literal with a language tag. Comparison reflects language tag rules so "foo"@en matches "EN-gb".
jfn:bnode(?x) Return the blank node label if ?x is a blank node.

Mathematical Functions

Function name Description
jfn:min(num1, num2) Return the minimum of two expressions evaluating to numbers.
jfn:max(num1, num2) Return the maximum of two expressions evaluating to numbers.
jfn:round(v) Return the nearest integer value to the argument.
jfn:abs(v) Return the absolute value.
jfn:floor(v) Return the greatest integer value less than the argument (as a double).
jfn:ceiling(v) Return the smallest integer value than the argument (as a double).

Miscellaneous Functions

Function name Description
jfn:now() Current time.  Actually, the time the query started.
jfn:sha1sum(resource) Calculate the SHA1 checksum of a literals or URI.

More functions will be added. Contributions welcome.

Writing a SPARQL custom function is implementation dependent and requires some understanding of the ARQ query engine being used. ARQ has a basic, general purpose query engine but it is possible to add new engines, or override functionality in the basic query engine. See ARQ Query Engine Design.

Function Registry

Functions can be installed into the function registry by the application.

@@add details - see javadoc for now.

Dynamically Loaded Functions

URIs for functions in the (fake) URI scheme java: are dynamically loaded. The class name forms the scheme specific part of the URI.

The ARQ function library uses this mechanism.  The namespace of the ARQ function library is <java:com.hp.hpl.jena.query.function.library.> (note the trailing dot).

PREFIX jfn: <java:com.hp.hpl.jena.query.function.library.>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?v
{  ?x rdfs:label ?v .
    FILTER jfn:langeq(?v, "en" )
}

ARQ Documentation Page