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. Functions and extensions can be registered or dynamically loaded.
More functions will be added. Contributions welcome.
Applications can also provide their own functions.
The prefix jfn
is
<java:com.hp.hpl.jena.query.function.library.>
.
Note the final dot in the prefix.
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. |
String Functions
Function name | Description |
---|---|
jfn:concat(string1,
string2) |
Return the concatenation of two strings. |
jfn:substring(string,
beginIndex [,endIndex]) |
Returns the substring of a string, given
by beginIndex (integer) and, optionally, an
endIndex .
Absence of endIndex means to end of string. Strings are indexed from zero. |
jfn:substr(string,
beginIndex [,endIndex]) |
Synonym for jfn:substring. |
jfn:strlen() |
Return the length of a string. |
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 literal or URI. |
Debugging Functions
Debugging functions can be inserted into queries as extra
FILTER
clauses. They don't affect query
results (they always return true) but they print information that
can be helpful in understanding what's happening.
Function name | Description |
---|---|
jfn:print(expr,
...) |
Print the evaluated expressions. With no arguments, prints the current solution. Always returns true. |
jfn:trace(expr) |
Print the expression with values substituted for variables if the variable is set and print result of evaluation, including whether there was an evaluation exception. Always returns true so it does not filter based on the expression. |
Example:
{ ... FILTER jfn:print() # Print the solution FILTER jfn:trace(expression) # Evaluate and print the expression FILTER expression # Now use the expression to filter solutions ... }
The prefix list:
is http://www.jena.hpl.hp.com/ARQ/list#
.
Property name | Description |
---|---|
list:member |
Membership of an RDF List (RDF Collection) |
rdfs:member |
Membershp of an RDF
Container (rdf:Bag, rdf:Seq, rdf:Alt) |
The prefix jext
is
<java:com.hp.hpl.jena.query.extension.library.>
.
Extensions are not part of SPARQL; the application will need to use the ARQ query language (a superset of SPARQL). Unlike a value function, an extension can set variables and generate multiple solutions. Extensions are written:
EXT q:name(?a, ?b, ?c)
Note the final dot in the prefix.
Extension name | Description |
---|---|
jext:list(list, member) |
The argument list must be bound by this point in the query or a constant expression. If list is bound or a URI, and member a variable, generate solutions with member bound to each element in the list. If member is bound or a constant expression, test to see if a member of the list. |
jext:bag(bag,
member) |
The argument bag must be bound by this point in the query or a constant expression. If bag is bound or a URI, and member a variable, generate solutions with member bound to each element in the bag. If member is bound or a constant expression, test to see if a member of the list. |
jext:seq(seq,
member) |
The argument seq must be bound by this point in the query or a constant expression. If seq is bound or a URI, and member a variable, generate solutions with member bound to each element in the sequence. If member is bound or a constant expression, test to see if a member of the list. |
jext:alt(alt,
member) |
The argument alt must be bound by this point in the query or a constant expression. If alt is bound or a URI, and member a variable, generate solutions with member bound to each element in the alt . If member is bound or a constant expression, test to see if a member of the list. |