Query Functions
This page describes all query functions supported by Stardog. For information on implementing your own please see the guide in the Extending Stardog chapter.
Page Contents
Stardog Function Namespaces
Stardog supports all of the functions in SPARQL, as well as some others from XPath and SWRL. Any of these functions can be used in queries or rules. Function names don’t require namespace prefixes in general unless ambiguity is present. XPath functions take precedence when resolving functions without namespace prefixes. Some functions appear in multiple namespaces, but all of the namespaces will work:
Prefix | Namespace |
---|---|
stardog | tag:stardog:api:functions: |
fn | http://www.w3.org/2005/xpath-functions# |
math | http://www.w3.org/2005/xpath-functions/math# |
swrlb | http://www.w3.org/2003/11/swrlb# |
leviathan | http://www.dotnetrdf.org/leviathan# |
afn | http://jena.hpl.hp.com/ARQ/function# |
Stardog Query Functions
The function names and URIs supported by Stardog are included below. Some of these functions exist in SPARQL natively, which just means they can be used without an explicit namespace. Some of the functions have a URI that can be used, but they are also overloaded arithmetic operators. For example, if you want to add two day time durations, you can simply use the expression ?duration1 + ?duration2
instead of swrlb:addDayTimeDurations(?duration1 + ?duration2)
.
Table of Custom Stardog Functions
Function | Description |
---|---|
tag:stardog:api:analytics:accuracy | Aggregate which computes percentage of times two variables have different values. Used with machine learning. Example: accuracy(?original, ?inferred) . In SPARQL: sum(if(?a = ?b, 1, 0)) / count(*) |
tag:stardog:api:functions:cosh | Hyperbolic cosine |
tag:stardog:api:gmean | Geometric mean aggregate |
tag:stardog:api:identifier | MD5 hash as IRI of RDF terms (3 or 4) to be used as a statement identifier. Example: identifier(?s, ?p, ?o) |
tag:stardog:api:index | Lookup an array element by 0-based index. Example index(split("John Doe"), 1) will return "Doe" . |
tag:stardog:api:functions:isValid | Check the validity of an RDF value |
tag:stardog:api:functions:localname | Alias to afn:localname |
tag:stardog:api:analytics:mae | Aggregate which computes on average, how different are the numeric values of two variables. In SPARQL: sum(abs(?a - ?b)) / count(*) . |
tag:stardog:api:analytics:mse | Aggregate which computes on average, how much is the squared difference between the numeric values of two variables. In SPARQL: sum((?a - ?b) * (?a - ?b)) / count(*) . |
tag:stardog:api:analytics:rmse | Aggregate which computes the square root of the mean square error. In SPARQL: sqrt(sum((?a - ?b) * (?a - ?b)) / count(*)) . |
tag:stardog:api:set | Aggregate function which constructs an array literal from accumulated bindings. Example: set(?element) |
tag:stardog:api:functions:sinh | Hyperbolic sine |
tag:stardog:api:split | Split a string by a regex delimiter. An array literal is returned. Example: split("John Doe", " ") . An optional third integer argument limits the number of times the pattern will be matched when splitting the string. |
tag:stardog:api:functions:tanh | Hyperbolic tangent |
tag:stardog:api:template | Template function used in virtual graph mappings, e.g. template("prefix:{variable}") |
tag:stardog:api:functions:toDegrees | Alias to leviathan:radians-to-degrees |
tag:stardog:api:functions:toRadians | Alias to leviathan:degrees-to-radians |
Table of Stardog Function Names & URIs
Property Functions
In addition to functions defined in SPARQL, Stardog also supports property functions, represented as special predicates.
Function | Description |
---|---|
tag:stardog:api:list:length | Computes length of RDF list |
tag:stardog:api:list:member | Performes membership operations on RDF lists |
tag:stardog:api:property:textMatch or http://jena.hpl.hp.com/ARQ/property#textMatch | Performs full text match against search index |
tag:stardog:frequency:predicate | Computes frequency of predicates |
tag:stardog:frequency:class | Computes frequency of classes |
tag:stardog:frequency:graph | Computes frequency of graphs |