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
trueifvaris bound to a value. Returnsfalseotherwise. Variables with the valueNaNorINFare considered bound.Example:
bound(?date) # false
Details: https://www.w3.org/TR/sparql11-query/#func-bound
if
RDFterm if(expression1, expression2, expression3)
The
IFfunction formevaluates expression1, interprets it as a effective boolean value, then returns the value ofexpression2if the EBV istrue, otherwise it returns the value ofexpression3. Only one ofexpression2andexpression3is evaluated. If evaluating the first argument raises an error, then an error is raised for the evaluation of theIFexpression.Example:
x=2; IF(?x = 2, "yes", "no") # yes
Details: https://www.w3.org/TR/sparql11-query/#func-if
coalesce
RDFterm coalesce(expression, ....)
The
COALESCEfunction form returns the RDF term value of the firstexpressionthat 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
ORofexpression. Note that logical-or operates on the effective boolean value of its arguments.
TheORfunction 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
ANDofexpression. Note that logical-and operates on the effective boolean value of its arguments.
TheANDfunction 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
trueifterm1andterm2are the same RDF term; produces a type error if the arguments are both literal but are not the same RDF term; returnsfalseotherwise.
TheEQUALfunction is equivalent to the SPARQL expression:term1 = term2Example:
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
trueifterm1andterm2are the same RDF term; returnsfalseotherwise.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
INoperator tests whether thetermis found in the values of list ofexpressions. 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 INoperator tests whether thetermis not found in the values of list ofexpressions. The test is done with "!=" operator, which tests for not the same value, as determined by the operator mapping.
TheNOT INoperator 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
trueif term is an IRI. Returnsfalseotherwise. 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
trueiftermis a blank node. Returnsfalseotherwise.Example:
x=_:id; isBlank(?x) # true
Details: https://www.w3.org/TR/sparql11-query/#func-isBlank
isLiteral
boolean isLiteral (RDFterm term)
Returns
trueiftermis a literal. Returnsfalseotherwise.Example:
x="value"; isLiteral(?x) # true
Details: https://www.w3.org/TR/sparql11-query/#func-isLiteral
isNumeric
boolean isNumeric (RDFterm term)
Returns
trueiftermis a numeric value. Returnsfalseotherwise.termis 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 ofrsrc(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""ifltrlhas no language tag.
datatype
iri datatype (literal ltrl)
Returns the
datatypeIRI of a literal.
- If
ltrlis a typed literal, return the datatypeIRI.- If
ltrlis a simple literal, returnstring- If
ltrlis literal with a language tag, returnrdf:langString
IRI
iri IRI(literal)
iri IRI(string)
iri IRI(iri)
iri URI(literal)
iri URI(string)
iri URI(iri)
The
IRIfunction constructs anIRIby resolving the string argument. The IRI is resolved against the base IRI of the query and must result in an absolute IRI.
TheURIfunction is a synonym forIRI.
Passing any RDF term other than a simple literal,xsd:stringor 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
BNODEfunction 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 theno argumentform is used, every call results in a distinct blank node. If the form with aliteralis used, every call results in distinct blank nodes for different simple literals.
strdt
literal strdt (literal lexicalForm, IRI datatypeIRI)
The
STRDTfunction constructs a literal withlexicalFormanddata typeas specified by the arguments.
strlang
literal strlang (literal lexicalForm, literal langTag)
The
STRLANGfunction constructs a literal withlexicalFormandlanguage tagas 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:integerequal to the length in characters of the lexical form ofstr.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
sourcestring beginning at the position marked bystartingLoc, and will have alengthas 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
trueif the lexical form ofarg1starts with the lexical form ofarg2, otherwise it returnsfalse. 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
trueif the lexical form ofarg1ends with the lexical form ofarg2, otherwise it returnsfalse. 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
trueif the lexical form ofarg1contains the lexical form ofarg2, otherwise it returnsfalse. 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
arg1before the compare stringarg2. 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
arg1after the comparearg2. 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 thefn:encode-for-urifunction.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 typexsd: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
trueiflanguage-tag(first argument) matcheslanguage-range(second argument) per the basic filtering scheme defined in [RFC4647] section 3.3.1.language-rangeis a basic language range per Matching of Language Tags [RFC4647] section 2.1. Alanguage-rangeof"*"matches any non-emptylanguage-tagstring.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
textmatches thepattern. Thepatternmay contain different special characters.
The tables below lists the most common special characters:
| Special characters | Meaning |
|---|---|
(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 characters | Meaning |
|---|---|
* | 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 |
\1 | Retrieves the saved match |
(?:pattern) | Matches pattern but does not save the match |
| Special characters | Meaning |
|---|---|
^ | Start of string, or start of line in multi-line pattern |
\A | Start of string |
\b \B | Word boundary / Not word boundary |
\d \D | Digits [0-9] / Nondigit characters [^0-9] |
\p{ name } | Matches any single character in the Unicode general category or named block specified by name |
\w \W | The 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 |
\Z | End 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
patterninargwithreplacement.patternis interpreted the same way as in REGEX. An optionalflagsaffects 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:dateTimevalue 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
argas an integer.
month
integer month (dateTime arg)
Returns the month part of
argas an integer.
day
integer day (dateTime arg)
Returns the day part of
argas an integer.
hours
integer hours (dateTime arg)
Returns the hours part of
argas 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
argas anxsd: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 \ To | xsd:string | xsd:float | xsd:double | xsd:decimal | xsd:integer | xsd:dateTime | xsd:boolean |
|---|---|---|---|---|---|---|---|
xsd:string | Y | M | M | M | M | M | M |
xsd:float | Y | Y | Y | M | M | N | Y |
xsd:double | Y | Y | Y | M | M | N | Y |
xsd:decimal | Y | Y | Y | Y | Y | N | Y |
xsd:integer | Y | Y | Y | Y | Y | N | Y |
xsd:dateTime | Y | N | N | N | N | Y | N |
xsd:boolean | Y | Y | Y | Y | Y | N | Y |
IRI | Y | N | N | N | N | N | N |
literal | Y | M | M | M | M | M | M |
boolean
boolean boolean(variable val)
Casts
valto a Boolean value.
double
double double(variable val)
Casts
valto a Double value.
float
float float(variable val)
Casts
valto a Float value.
decimal
decimal decimal(variable val)
Casts
valto a Decimal value.
integer
integer integer(variable val)
Casts
valto an Integer value.
dateTime
dateTime dateTime(variable val)
Casts
valto a Date-Time value.
string
string string(variable val)
Casts
valto a String value.
IRI
IRI = IRI(variable val)
Casts
valto an IRI value.
literal
literal literal(variable val)
Casts
valto a Literal value.