SPARQL allows custom functions in expressions so that queries can be used on domainspecific data. SPARQL defines a function by URI (or prefixed name) in FILTER expressions. ARQ provides a function library and supports applicationprovided functions. Functions and property functions can be registered or dynamically loaded.
Applications can also provide their own functions.
ARQ also provides an implementation the Leviathan Function Library.
ARQ supports the scalar functions and operators from "XQuery 1.0 and XPath 2.0 Functions and Operators v3.1".
Functions in involving sequences are not supported.
See XSD Support for details of datatypes and functions currenty supported. To check the exact current registrations, see function/StandardFunctions.java.
See also the property functions library page.
The prefix afn
is <http://jena.apache.org/ARQ/function#>
.
(the old prefix of <http://jena.hpl.hp.com/ARQ/function#>
continues to
work. Applications are encouraged to switch.)
Direct loading using a URI prefix of
<java:org.apache.jena.sparql.function.library.>
(note the final
dot) is deprecated.
The prefix fn
is <http://www.w3.org/2005/xpathfunctions#>
(the
XPath and XQuery function namespace).
The prefix math
is <http://www.w3.org/2005/xpathfunctions/math#>
.
The prefix agg:
is <http://jena.apache.org/ARQ/function/aggregate#>
.
The statistical aggregates are provided are:
agg:stdev
, agg:stdev_samp
, agg:stdev_pop
,
agg:variance
, agg:var_samp
, agg:var_pop
These are modelled after SQL aggregate functions STDEV
, STDEV_SAMP
, STDEV_POP
,
VARIANCE
, VAR_SAMP
, VAR_POP
.
These, as keywords, are available in ARQ's extended SPARQL (parse using Syntax.syntaxARQ
).
Most of these have equivalents, or near equivalents, in SPARQL or as an XQuery function and are to be preferred. These ARQspecific versions remain for compatibility.
RDF Graph Functions
Function name  Description  Alternative 

afn:bnode(?x) 
Return the blank node label if ?x is a blank node.  STR(?x) 
afn:localname(?x) 
The local name of ?x  REPLACE(STR(?x), "^(.*)(/#)([^#/]*)$", "$3") 
afn:namespace(?x) 
The namespace of ?x  REPLACE(STR(?x), "^(.*)(/#)([^#/]*)$", "$1") 
The prefix and local name of a IRI is based on splitting the IRI, not on any prefixes in the query or dataset.
String Functions
Function name  Description  Alternative 

afn:sprintf(format, v1, v2, ...) 
Make a string from the format string and the RDF terms.  
afn:substr(string, startIndex [,endIndex]) 
Substring, Java style using startIndex and endIndex . 

afn:substring 
Synonym for afn:substr  
afn:strjoin(sep, string ...) 
Concatenate string together, with a separator.  
afn:sha1sum(resource) 
Calculate the SHA1 checksum of a literal or URI  SHA1(STR(resource)) 
Notes:
fn:substring
operation takes an optional length, like C#
but different from Java, where it is the endIndex of the first
character after the substring.afn:substr
uses Javastyle startIndex
and endIndex
.Mathematical Functions
Function name  Description  Alternative 

afn:min(num1, num2) 
Return the minimum of two numbers  fn:min 
afn:max(num1, num2) 
Return the maximum of two numbers  fn:max 
afn:pi() 
The value of pi, as an XSD double  math:pi() 
afn:e() 
The value of e, as an XSD double  math:exp(1) 
afn:sqrt(num) 
The square root of num  math:sqrt 
Miscellaneous Functions
Function name  Description  Alternative 

afn:now() 
Current time. Actually, the time the query started.  NOW() 
afn:sha1sum(resource) 
Calculate the SHA1 checksum  SHASUM 