Skip to main content

Function Reference

Functions are used throughout the GeneTegra Query Builder. They are used to define constraints in Custom Relationships, conditions in Query Filters, and calculated values in Projection Expressions.

This page describes the Functions that are supported by GeneTegra.
Some Functions may not appear in all situations, depending on the context.

SPARQL Functions​

GeneTegra is designed to support all SPARQL 1.1 functions.

Details: https://www.w3.org/TR/sparql11-query/#SparqlOps | https://en.wikibooks.org/wiki/SPARQL/Expressions_and_Functions

bound​

boolean  bound(variable var)

Returns true if var is bound to a value. Returns false otherwise. Variables with the value NaN or INF are considered bound.

Example: bound(?date) # false
Details: https://www.w3.org/TR/sparql11-query/#func-bound

if​

RDFterm  if(expression1, expression2, expression3)

The IF function form evaluates expression1, interprets it as a effective boolean value, then returns the value of expression2 if the EBV is true, otherwise it returns the value of expression3. Only one of expression2 and expression3 is evaluated. If evaluating the first argument raises an error, then an error is raised for the evaluation of the IF expression.

Example: x=2; IF(?x = 2, "yes", "no") # yes
Details: https://www.w3.org/TR/sparql11-query/#func-if

coalesce​

RDFterm  coalesce(expression, ....)

The COALESCE function form returns the RDF term value of the first expression that evaluates without error. In SPARQL, evaluating an unbound variable raises an error. If none of the arguments evaluates to an RDF term, an error is raised. If no expressions are evaluated without error, an error is raised.

Example: x=2; COALESCE(1/0, ?x) # 2
Details: https://www.w3.org/TR/sparql11-query/#func-if

or (Logical OR)​

boolean  or(boolean expression, ...)

Returns a logical OR of expression. Note that logical-or operates on the effective boolean value of its arguments.
The OR function is equivalent to the SPARQL expression: expression1 || expression2 || ...

Example: OR(false, true) # true
Details: https://www.w3.org/TR/sparql11-query/#func-logical-or

and (Logical AND)​

boolean  and(boolean expression, ...)

Returns a logical AND of expression. Note that logical-and operates on the effective boolean value of its arguments.
The AND function is equivalent to the SPARQL expression: expression1 && expression2 && ...

Example: AND(true, false) # false
Details: https://www.w3.org/TR/sparql11-query/#func-logical-and

equal​

boolean  equal(RDFterm term1, RDFterm term2)

Returns true if term1 and term2 are the same RDF term; produces a type error if the arguments are both literal but are not the same RDF term; returns false otherwise.
The EQUAL function is equivalent to the SPARQL expression: term1 = term2

Example: x="Value", y="Value"; EQUAL(?x, ?y) # true
Details: https://www.w3.org/TR/sparql11-query/#func-RDFterm-equal

sameTerm​

boolean  sameTerm (RDFterm term1, RDFterm term2)

Returns true if term1 and term2 are the same RDF term; returns false otherwise.

Example: x="Value1", y="Value2"; FILTER (sameTerm(?x, ?y)) # false
Details: https://www.w3.org/TR/sparql11-query/#func-sameTerm

in​

boolean  in(RDFterm term, expression, ...)

The IN operator tests whether the term is found in the values of list of expressions. The test is done with "=" operator, which tests for the same value, as determined by the operator mapping.

The IN operator is equivalent to the SPARQL expression: (term = expression1) || (term = expression2) || ...

Example: x="Value1"; IN(?x, "Value1", "Value2", "Value3") # true
Details: https://www.w3.org/TR/sparql11-query/#func-in

notIn​

boolean  notIn(RDFterm term, expression, ...)

The NOT IN operator tests whether the term is not found in the values of list of expressions. The test is done with "!=" operator, which tests for not the same value, as determined by the operator mapping.
The NOT IN operator is equivalent to the SPARQL expression: (term != expression1) && (term != expression2) && ...
NOT IN (...) is equivalent to !(IN (...)).\

Example: x="Value1"; NOTIN(?x, "Value1", "Value2", "Value3") # false
Details: https://www.w3.org/TR/sparql11-query/#func-not-in

Functions on RDF Terms​

isIRI, isURI​

 boolean  isIRI (RDFterm term)
boolean isURI (RDFterm term)

Returns true if term is an IRI. Returns false otherwise. isURI is an alternate spelling for the isIRI operator. NOT IN (...) is equivalent to !(IN (...)).\

Example: x=<http://infotechsoft.com>; isIRI(?x) # true
Details: https://www.w3.org/TR/sparql11-query/#func-isIRI

isBlank​

boolean  isBlank (RDFterm term)

Returns true if term is a blank node. Returns false otherwise.

Example: x=_:id; isBlank(?x) # true
Details: https://www.w3.org/TR/sparql11-query/#func-isBlank

isLiteral​

boolean  isLiteral (RDFterm term)

Returns true if term is a literal. Returns false otherwise.

Example: x="value"; isLiteral(?x) # true
Details: https://www.w3.org/TR/sparql11-query/#func-isLiteral

isNumeric​

boolean  isNumeric (RDFterm term)

Returns true if term is a numeric value. Returns false otherwise. term is numeric if it has an appropriate datatype and has a valid lexical form, making it a valid argument to functions and operators taking numeric arguments.

str​

literal  str (literal ltrl)
literal str (IRI rsrc)

Returns the lexical form of ltrl (a literal); returns the codepoint representation of rsrc (an IRI). This is useful for examining parts of an IRI, for instance, the host-name.

lang​

literal  lang (literal ltrl)

Returns the language tag of ltrl, if it has one. It returns "" if ltrl has no language tag.

datatype​

iri  datatype (literal ltrl)

Returns the datatype IRI of a literal.

  • If ltrl is a typed literal, return the datatype IRI.
  • If ltrl is a simple literal, return string
  • If ltrl is literal with a language tag, return rdf:langString

IRI​

 iri  IRI(literal)
iri IRI(string)
iri IRI(iri)
iri URI(literal)
iri URI(string)
iri URI(iri)

The IRI function constructs an IRI by resolving the string argument. The IRI is resolved against the base IRI of the query and must result in an absolute IRI.
The URI function is a synonym for IRI.
Passing any RDF term other than a simple literal, xsd:string or an IRI is an error.

Example: x="http://infotechsoft.com"; IRI(?x) # <http://infotechsoft.com>
Details: https://www.w3.org/TR/sparql11-query/#func-iri

bnode​

blankNode  bnode()
blankNode bnode(literal)
blankNode bnode(string)

The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions. If the no argument form is used, every call results in a distinct blank node. If the form with a literal is used, every call results in distinct blank nodes for different simple literals.

strdt​

literal  strdt (literal lexicalForm, IRI datatypeIRI)

The STRDT function constructs a literal with lexicalForm and data type as specified by the arguments.

strlang​

literal  strlang (literal lexicalForm, literal langTag)

The STRLANG function constructs a literal with lexicalForm and language tag as specified by the arguments.

UUID​

iri  UUID ()

Return a fresh IRI from the UUID URN scheme. Each call of UUID() returns a different UUID. It must not be the "nil" UUID (all zeroes). The variant and version of the UUID is implementation dependent.

Example: UUID() # <urn:uuid:b9302fb5-642e-4d3b-af19-29a8f6d894c9>
Details: https://www.w3.org/TR/sparql11-query/#func-struuid

STRUUID​

simpleLiteral  STRUUID ()

Return a string that is the scheme specific part of UUID. That is, as a simple literal, the result of generating a UUID, converting to a simple literal and removing the initial urn:uuid:.

Example: STRUUID() # "73cd4307-8a99-4691-a608-b5bda64fb6c1"
Details: https://www.w3.org/TR/sparql11-query/#func-struuid

Functions on Strings​

strlen​

integer  strlen (stringLiteral str)

Returns an xsd:integer equal to the length in characters of the lexical form of str.

Example: var="1234567"; STRLEN( ?var ) # 7
Details: https://www.w3.org/TR/sparql11-query/#func-strlen

substr​

stringLiteral  substr (stringLiteral source, integer startingLoc)
stringLiteral substr (stringLiteral source, integer startingLoc, integer length)

Returns a substring of source string beginning at the position marked by startingLoc, and will have a length as indicated.
The index of the first character in a strings is 1.

Example: var="ABCDEFG"; SUBSTR( ?var, 2, 3 ) # "BCD"
Details: https://www.w3.org/TR/sparql11-query/#func-substr

ucase​

stringLiteral  ucase (stringLiteral str)

Returns a string literal whose lexical form is the upper case of the lexcial form of str.

Example: UCASE("Abc") # ABC
Details: https://www.w3.org/TR/sparql11-query/#func-ucase

lcase​

stringLiteral  lcase(stringLiteral str)

Returns a string literal whose lexical form is the lower case of the lexcial form of str.

Example: LCASE("Abc") # abc
Details: https://www.w3.org/TR/sparql11-query/#func-lcase

strstarts​

boolean  strstarts(stringLiteral arg1, stringLiteral arg2)

Returns true if the lexical form of arg1 starts with the lexical form of arg2, otherwise it returns false. The arguments must be argument compatible otherwise an error is raised.

Example: STRSTARTS( "ABCDEFGH", "ABC" ) # true
Details: https://www.w3.org/TR/sparql11-query/#func-strstarts

strends​

boolean  strends(stringLiteral arg1, stringLiteral arg2)

Returns true if the lexical form of arg1 ends with the lexical form of arg2, otherwise it returns false. The arguments must be argument compatible otherwise an error is raised.

Example: STRENDS( "ABCDEFGH", "FGH" ) # true
Details: https://www.w3.org/TR/sparql11-query/#func-strends

contains​

boolean  contains(stringLiteral arg1, stringLiteral arg2)

Returns true if the lexical form of arg1 contains the lexical form of arg2, otherwise it returns false. The arguments must be argument compatible otherwise an error is raised.

Example: CONTAINS( "ABCDEFGH", "DEF" ) # true
Details: https://www.w3.org/TR/sparql11-query/#func-contains

strbefore​

literal  strbefore(stringLiteral arg1, stringLiteral arg2)

Returns the part of the string arg1 before the compare string arg2. If there is no such occurrence, an empty simple literal is returned. The arguments must be argument compatible otherwise an error is raised.

Example: STRBEFORE( "ABCDEFGH", "DEF" ) # "ABC"
Details: https://www.w3.org/TR/sparql11-query/#func-strbefore

strafter​

literal  strafter(stringLiteral arg1, stringLiteral arg2)

Returns the part of the string arg1 after the compare arg2. If there is no such occurrence, an empty simple literal is returned. The arguments must be argument compatible otherwise an error is raised.

Example: STRAFTER( "ABCDEFGH", "DEF" ) # "GH"
Details: https://www.w3.org/TR/sparql11-query/#func-strafter

encode_for_uri​

simpleLiteral  encode_for_uri(stringLiteral ltrl)

Converts the special characters in the ltrl, to be able to use it in an web URL. It returns a simple literal with the lexical form obtained from the lexical form of its input after translating reserved characters according to the fn:encode-for-uri function.

Example: ENCODE_FOR_URI( "ABC DËFGH" ) # "ABC%20D%C3%8BFGH"
Details: https://www.w3.org/TR/sparql11-query/#func-encode

concat​

stringLiteral  concat(stringLiteral ltrl1, ..., stringLiteral ltrln)

Returns the concatenation of two or more strings (ltrl1...ltrln). If all input literals are typed literals of type string, then the returned literal is also of type xsd:string, if all input literals are plain literals with identical language tag, then the returned literal is a plain literal with the same language tag, in all other cases, the returned literal is a simple literal.

Example: CONCAT( "ABCDEFGH", "-", "XYZ" ) # "ABCDEFGH-XYZ"
Details: https://www.w3.org/TR/sparql11-query/#func-concat

langMatches​

 boolean  langMatches (simpleLiteral language-tag, simpleLiteral language-range)

Returns true if language-tag (first argument) matches language-range (second argument) per the basic filtering scheme defined in [RFC4647] section 3.3.1. language-range is a basic language range per Matching of Language Tags [RFC4647] section 2.1. A language-range of "*" matches any non-empty language-tag string.

Example: label="Bonjour"@fr; LANGMATCHES( LANG(?label), "fr" ) # true
Details: https://www.w3.org/TR/sparql11-query/#func-langMatches

regex​

 boolean  regex (stringLiteral text, simpleLiteral pattern)
boolean regex (stringLiteral text, simpleLiteral pattern, simpleLiteral flags)

Checks if the text matches the pattern. The pattern may contain different special characters.
The tables below lists the most common special characters:

Special charactersMeaning
(a|b)a or b
[abc]Range (a or b or c)
[^abc]Not (a or b or c)
[a-q]Lower case letter from a to q
[A-Q]Upper case letter from A to Q
[0-7]Digit from 0 to 7
.Wildcard: Matches any single character except \n.

 

Special charactersMeaning
*0 or more
+1 or more
?0 or 1
{3}Exactly 3
{3,}3 or more
{3,5}3, 4 or 5
(pattern)Matches pattern and saves the match
\1Retrieves the saved match
(?:pattern)Matches pattern but does not save the match
Special charactersMeaning
^Start of string, or start of line in multi-line pattern
\AStart of string
\b \BWord boundary / Not word boundary
\d \DDigits [0-9] / Nondigit characters [^0-9]
\p{ name }Matches any single character in the Unicode general category or named block specified by name
\w \WThe characters [A-Za-z0-9_] / None of the characters [A-Za-z0-9_]
\<Start of word
\>End of word
$End of string, or end of line in multi-line pattern
\ZEnd of string

Example:
Details: https://www.w3.org/TR/sparql11-query/#func-regex | https://en.wikibooks.org/wiki/SPARQL/Expressions_and_Functions

The flag is optional. Flag "i" means the match is case-insensitive.

replace​

 stringLiteral  replace (stringLiteral arg, simpleLiteral pattern, simpleLiteral replacement )
stringLiteral replace (stringLiteral arg, simpleLiteral pattern, simpleLiteral replacement, simpleLiteral flags)

Returns the string after replacing all occurrences of pattern in arg with replacement. pattern is interpreted the same way as in REGEX. An optional flags affects the regular expression pattern.

Example: REPLACE( "ABCDEFGH", "DEF", "_def_" ) # "ABC_def_GH"
         REPLACE( "ABCDEFGH", "[AEIOU]", "" ) # removes all the vowels from the original string.
Details:

Functions on Numerics​

abs​

 numeric  abs (numeric term)

Returns the absolute value of term. An error is raised if arg is not a numeric value.

round​

 numeric  round (numeric term)

Returns the number with no fractional part that is closest to the term. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if term is not a numeric value.

ceil​

 numeric  ceil (numeric term)

Returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of arg. An error is raised if arg is not a numeric value.

floor​

 numeric  floor (numeric term)

Returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of arg. An error is raised if arg is not a numeric value.

rand​

 double  rand ()

Returns a pseudo-random number between 0 (inclusive) and 1.0e0 (exclusive). Different numbers can be produced every time this function is invoked. Numbers should be produced with approximately equal probability.

Mathematical Functions​

add​

 numeric  add(numeric left, numeric right)

Returns the numeric sum of its operands ($left + $right)

Example: add(1, 2) # 3

subtract​

 numeric  subtract(numeric left, numeric right)

Returns the numeric difference of its operands ($left - $right)

Example: subtract(1, 2) # -1

multiply​

 numeric  multiply(numeric left, numeric right)

Returns the numeric product of its operands ($left * $right)

Example: multiply(1, 2) # 2

divide​

 numeric  divide(numeric left, numeric right)

Returns the numeric quotient of its operands ($left / $right)

Example: divide(1, 2) # 0.5

Functions on Dates and Times​

now​

 dateTime  now ()

Returns an xsd:dateTime value for the current query execution. All calls to this function in any one query execution must return the same value. The exact moment returned is not specified.

year​

 integer  year (dateTime arg)

Returns the year part of arg as an integer.

month​

 integer  month (dateTime arg)

Returns the month part of arg as an integer.

day​

 integer  day (dateTime arg)

Returns the day part of arg as an integer.

hours​

 integer  hours (dateTime arg)

Returns the hours part of arg as an integer. The value is as given in the lexical form of the XSD dateTime.

minutes​

 integer  minutes (dateTime arg)

Returns the minutes part of the lexical form of arg. The value is as given in the lexical form of the XSD dateTime.

seconds​

 decimal  seconds (dateTime arg)

Returns the seconds part of the lexical form of arg.

timezone​

 dayTimeDuration  timezone (dateTime arg)

Returns the timezone part of arg as an xsd:dayTimeDuration. Raises an error if there is no timezone.

Hash Functions​

MD5​

 simpleLiteral  MD5 (simpleLiteral arg)
simpleLiteral MD5 (string arg)

Returns the MD5 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the xsd:string. Hex digits should be in lower case.

SHA1​

 simpleLiteral  SHA1 (simpleLiteral arg)
simpleLiteral SHA1 (string arg)

Returns the SHA1 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the xsd:string. Hex digits should be in lower case.

SHA256​

 simpleLiteral  SHA256 (simpleLiteral arg)
simpleLiteral SHA256 (string arg)

Returns the SHA256 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the xsd:string. Hex digits should be in lower case.

SHA384​

 simpleLiteral  SHA384 (simpleLiteral arg)
simpleLiteral SHA384 (string arg)

Returns the SHA384 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the xsd:string. Hex digits should be in lower case.

SHA512​

 simpleLiteral  SHA512 (simpleLiteral arg)
simpleLiteral SHA512 (string arg)

Returns the SHA512 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the xsd:string. Hex digits should be in lower case.

Datatype Casting Functions​

XML Schema datatype casting functions are in the xsd (http://www.w3.org/2001/XMLSchema#) namespace.

Casting Compatibility Matrix​

The table below summarizes the casting operations that are always allowed (Y), never allowed (N) and dependent on the lexical value (M).

From \ Toxsd:stringxsd:floatxsd:doublexsd:decimalxsd:integerxsd:dateTimexsd:boolean
xsd:stringYMMMMMM
xsd:floatYYYMMNY
xsd:doubleYYYMMNY
xsd:decimalYYYYYNY
xsd:integerYYYYYNY
xsd:dateTimeYNNNNYN
xsd:booleanYYYYYNY
IRIYNNNNNN
literalYMMMMMM

boolean​

boolean  boolean(variable val)

Casts val to a Boolean value.

double​

double  double(variable val)

Casts val to a Double value.

float​

float  float(variable val)

Casts val to a Float value.

decimal​

decimal  decimal(variable val)

Casts val to a Decimal value.

integer​

integer  integer(variable val)

Casts val to an Integer value.

dateTime​

dateTime dateTime(variable val)

Casts val to a Date-Time value.

string​

string  string(variable val)

Casts val to a String value.

IRI​

IRI = IRI(variable val)

Casts val to an IRI value.

literal​

literal  literal(variable val)

Casts val to a Literal value.