Link Search Menu Expand Document
Start for Free

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
  1. Stardog Function Namespaces
  2. Stardog Query Functions
    1. Table of Custom Stardog Functions
    2. Table of Stardog Function Names & URIs
  3. Property Functions

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

Function name Recognized URIs and Symbols
abs ABS, fn:numeric-abs, swrlb:abs
accuracy tag:stardog:api:analytics:accuracy
acos math:acos, leviathan:cos-1
addDayTimeDurations +, swrlb:addDayTimeDurations
addDayTimeDurationToDate +, swrlb:addDayTimeDurationToDate
addDayTimeDurationToDateTime +, swrlb:addDayTimeDurationToDateTime
addDayTimeDurationToTime +, swrlb:addDayTimeDurationToTime
addYearMonthDurations +, swrlb:addYearMonthDurations
addYearMonthDurationToDate +, swrlb:addYearMonthDurationToDate
addYearMonthDurationToDateTime +, swrlb:addYearMonthDurationToDateTime
area http://www.opengis.net/def/function/geosparql/area
asin math:asin, leviathan:sin-1
atan math:atan
bnode BNODE
boolean xsd:boolean
bound BOUND
cartesian leviathan:cartesian
ceil CEIL, fn:numeric-ceil, swrlb:ceiling
coalesce COALESCE
concat CONCAT, fn:concat, swrlb:stringConcat
contains CONTAINS, fn:contains, swrlb:contains
containsIgnoreCase swrlb:containsIgnoreCase
cos math:cos, swrlb:cos, leviathan:cos
cosec leviathan:cosec
cosec-1 leviathan:cosec-1
cosh tag:stardog:api:functions:cosh
cotan leviathan:cotan
cotan-1 leviathan:cotan-1
cube leviathan:cube
datatype Datatype
date swrlb:date
dateTime xsd:dateTime
dateTimeStamp xsd:dateTimeStamp
day DAY, fn:day-from-dateTime, fn:day-from-date, fn:days-from-duration
dayTimeDuration swrlb:dayTimeDuration
decimal xsd:decimal
distance http://www.opengis.net/def/function/geosparql/distance[http://www.opengis.net/def/function/geosparql/distance]
divideDayTimeDuration /, swrlb:divideDayTimeDuration
divideYearMonthDuration /, swrlb:divideYearMonthDuration
double xsd:double
e leviathan:e, math:exp, afn:e
encode_for_uri ENCODE_FOR_URI, fn:encode-for-uri
factorial leviathan:factorial
float xsd:float
floor FLOOR, fn:numeric-floor, swrlb:floor
gmean tag:stardog:api:gmean
hours HOURS, fn:hours-from-dateTime, fn:hours-from-time, fn:hours-from-duration
identifier tag:stardog:api:identifier
if IF
index tag:stardog:api:index
integer xsd:integer
iri IRI, URI
isBlank isBlank, IsBNode
isIRI isIRI, IsURI
isLiteral isLiteral
isNumeric isNumeric
isresource IsResource
isValid tag:stardog:api:functions:isValid
lang Lang
langMatches langMatches
lcase LCASE, fn:lower-case, swrlb:lowerCase
localname tag:stardog:api:functions:localname, afn:localname
ln math:log, leviathan:ln
log, log10 math:log10, leviathan:log1
mae tag:stardog:api:analytics:mae
max fn:max, afn:max
md5 MD5, leviathan:md5hash
min fn:min, afn:min
minutes MINUTES, fn:minutes-from-dateTime, fn:minutes-from-time, fn:minutes-from-duration
mod swrlb:mod
month MONTH, fn:month-from-dateTime, fn:month-from-date, fn:months-from-duration
mse tag:stardog:api:analytics:mse
multiplyDayTimeDuration *, swrlb:multiplyDayTimeDuration
multiplyYearMonthDuration *, swrlb:multiplyYearMonthDuration
namespace tag:stardog:api:functions:namespace, afn:namespace
normalize-space fn:normalize-space, swrlb:normalizeSpace
now NOW
numeric-add fn:numeric-add
numeric-divide fn:numeric-divide, swrlb:divide
numeric-integer-divide fn:numeric-integer-divide, swrlb:integerDivide
numeric-multiply fn:numeric-multiply
numeric-round-half-to-even fn:numeric-round-half-to-even, swrlb:roundHalfToEven
numeric-subtract fn:numeric-subtract, swrlb:subtract
numeric-unary-minus fn:numeric-unary-minus, swrlb:unaryMinus
numeric-unary-plus fn:numeric-unary-plus, swrlb:unaryPlus
pi math:pi, afn:pi
pow math:pow, swrlb:pow, leviathan:pow
pythagoras leviathan:pythagoras
rand RAND, leviathan:rnd
reciprocal leviathan:reciprocal
regex Regex, fn:matches, swrlb:matches
relate http://www.opengis.net/def/function/geosparql/relate[http://www.opengis.net/def/function/geosparql/relate]
replace REPLACE, fn:replace, swrlb:replace
rmse tag:stardog:api:analytics:rmse
root leviathan:root
round ROUND, fn:numeric-round, swrlb:round
sameTerm sameTerm
sec leviathan:sec
sec-1 leviathan:sec-1
seconds SECONDS, fn:seconds-from-dateTime, fn:seconds-from-time, fn:seconds-from-duration
set tag:stardog:api:set, tag:stardog:api:analytics:set
sha1 SHA1
sha256 SHA256, leviathan:sha256hash
sha384 SHA384
sha512 SHA512
sin math:sin, swrlb:sin, leviathan:sin
sinh tag:stardog:api:functions:sinh
split tag:stardog:api:split
sq leviathan:sq
sqrt math:sqrt, afn:sqrt, leviathan:sqrt
stddev tag:stardog:api:functions:stddev2
str Str
strafter STRAFTER, fn:substring-after, swrlb:substringAfter
strbefore STRBEFORE, fn:substring-before, swrlb:substringBefore
strdt STRDT
strends STRENDS, fn:ends-with, swrlb:endsWith
string xsd:string
stringEqualIgnoreCase swrlb:stringEqualIgnoreCase
strlang STRLANG
strlen STRLEN, fn:string-length, swrlb:stringLength
strstarts STRSTARTS, fn:starts-with, swrlb:startsWith
struuid STRUUID
substr SUBSTR, fn:substring, swrlb:substring
subtractDates -, swrlb:subtractDates
subtractDayTimeDurationFromDate -, swrlb:subtractDayTimeDurationFromDate
subtractDayTimeDurationFromDateTime -, swrlb:subtractDayTimeDurationFromDateTime
subtractDayTimeDurationFromTime -, swrlb:subtractDayTimeDurationFromTime
subtractDayTimeDurations -, swrlb:subtractDayTimeDurations
subtractTimes -, swrlb:subtractTimes
subtractYearMonthDurationFromDate -, swrlb:subtractYearMonthDurationFromDate
subtractYearMonthDurationFromDateTime -, swrlb:subtractYearMonthDurationFromDateTime
subtractYearMonthDurations -, swrlb:subtractYearMonthDurations
tan math:tan, swrlb:tan
tanh tag:stardog:api:functions:tanh
template tag:stardog:api:template
ten leviathan:ten
time swrlb:time
timezone TIMEZONE, fn:timezone-from-dateTime, fn:timezone-from-date, fn:timezone-from-time
toDegrees tag:stardog:api:functions:toDegrees, leviathan:radians-to-degrees
toRadians tag:stardog:api:functions:toRadians, leviathan:degrees-to-radians
translate fn:translate, swrlb:translate
tz TZ
ucase UCASE, fn:upper-case, swrlb:upperCase
uuid UUID
within http://www.opengis.net/def/function/geosparql/within
year YEAR, fn:year-from-dateTime, fn:year-from-date, fn:years-from-duration
yearMonthDuration swrlb:yearMonthDuration

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 Performs 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
  1. To take the log of a number with a base other than e or 10, perform a change of base calculation (e.g., for log2(a), calculate ln(a) / ln(2)). 

  2. Note this function is stddev and not the more common sd or stdev