TopBraid SPARQLMotion Functions Library

Version 1.1.0

The following functions can be used either inside of LET and FILTER clauses within a SPARQL query, or as SPARQLMotion modules. For example, using the sml:cast function below in SPARQL to compute a new value and assign it to ?floatPrice, use the following syntax:

	SELECT *
	WHERE {
		?subject my:price ?price .
		LET (?floatPrice := smf:cast(?price, xsd:float)) .
	}

Overview

Module/Function Name
fn:abs
smf:buildURI
smf:cast
fn:ceiling
smf:countMatches
smf:countResults
smf:dbpedia
afn:e
fn:ends-with
fn:floor
smf:if
smf:indexOf
smf:isBound
smf:lastIndexOf
smf:localRange
afn:localname
fn:lower-case
fn:matches
afn:max
smf:maxCardinality
afn:min
smf:minCardinality
smf:name
afn:namespace
afn:now
smf:parseDate
afn:pi
smf:qname
fn:round
smf:setLanguage
fn:starts-with
fn:string-join
fn:string-length
smf:subString
afn:substr
fn:substring
smf:titleCase
smf:trim
fn:upper-case

Details


abs

URL: fn:abs 
Description: Returns the absolute value of the argument.

Arguments:
  • num () - The input value.
Returns: rdfs:Literal

buildURI

URL: smf:buildURI 
Description: Constructs a new URI resource by inserting the existing variable bindings into a template. The template can mention variable names in curly braces, such as "my:Instance-{?index}" would create "my:Instance-42" is ?index has the value 42. As an alternative to variable names, the function can take additional arguments after the template, the variables of which can be accessed using {?1}, {?2} etc. For example: smf:buildURI("my:Instance-{?1}-{?2}", ?day, ?month) would insert day and month at places {?1} and {?2}.

Arguments:
  • template (xsd:string) - The URI template such as "". If the template contains a full URI, then it must be wrapped by <...>, otherwise the system will treat it as a qname.
Returns: rdfs:Resource

cast

URL: smf:cast 
Description: Creates a new literal from an existing literal, but with a different datatype. This can, for example, be used to convert between floating point values and int values.

Arguments:
  • literal () - The "old" literal that shall be converted.
  • datatype () - The target datatype of the result, e.g. xsd:int.
Returns: rdfs:Literal

ceiling

URL: fn:ceiling 
Description: Returns the smallest integer value less than the argument (as a double).

Arguments:
  • num () - The input value.
Returns: xsd:double

countMatches

URL: smf:countMatches 
Description: Counts all occurences of a triple pattern based on ?subject, ?predicate, ?object input. Any of those can be unbound variables.

Arguments:
  • subject () - The subject to match or an unbound variable for a wildcard.
  • predicate () - The predicate to match or an unbound variable for a wildcard.
  • object () - The object to match or an unbound variable for a wildcard.
Returns:

countResults

URL: smf:countResults 
Description: Runs an nested SPARQL query and counts its results. Note that the nested query will reuse the variable bindings from its surrounding.

Arguments:
  • selectQuery () - The SPARQL Select query to execute (as a string).
Returns:

dbpedia

URL: smf:dbpedia 
Description: Attempts to get a DBPedia page for a string.

Arguments:
  • label (xsd:string) - The label to get a DBPedia resource for.
Returns: rdfs:Resource

e

URL: afn:e 
Description: Returns the value of e, as xsd:double.

Arguments:
Returns: xsd:double

ends-with

URL: fn:ends-with 
Description: Test whether string ends with substr.

Arguments:
  • text (xsd:string) - The string to search in.
  • substr (xsd:string) - The substring to check for.
Returns: xsd:boolean

floor

URL: fn:floor 
Description: Returns the greatest integer value less than the argument (as a double).

Arguments:
  • num () - The input value.
Returns: xsd:double

if

URL: smf:if 
Description: Evaluates a condition and depending on the outcome either returns the true argument or the false argument. This is comparable to Java's ... ? ... : ... notation.

Arguments:
  • condition (xsd:boolean) - The condition that shall be evaluated. If true then return the ?true argument, otherwise return ?else.
  • true () - The result if the conditions is true.
  • false () - The (optional) false branch.
Returns:

indexOf

URL: smf:indexOf 
Description: Gets the index of the first occurence of a certain substring in a given search string. Returns null if the substring is not found.

Arguments:
  • text (xsd:string) - The string to search in.
  • substr (xsd:string) - The sub string to search for.
Returns: xsd:int

isBound

URL: smf:isBound 
Description: Checks whether the input expression evaluates to a bound variable. This is similar to the built-in bound function of SPARQL, but bound expects a variable as argument and therefore can not be used to evaluate arbitrary nested functions.

Arguments:
  • node () - The argument or variable to evaluate.
Returns: xsd:boolean

lastIndexOf

URL: smf:lastIndexOf 
Description: Gets the last index of the first occurence of a certain substring in a given search string. Returns null if the substring is not found.

Arguments:
  • text (xsd:string) - The string to search in.
  • substr (xsd:string) - The sub string to search for.
Returns: xsd:int

localRange

URL: smf:localRange 
Description: Gets the local range of a property at a class. The function first checks for locally defined owl:allValuesFrom restrictions on the class or its superclasses. If none is found, it will try to use the global rdfs:range of the property. If this does not exist either, it will return null.

Arguments:
  • class (rdfs:Class) - The class to get the local range at.
  • property (rdf:Property) - The property to get the local range of.
Returns: rdfs:Class

localname

URL: afn:localname 
Description: Returns the local name of a URI resource. Based on splitting the IRI, not on any prefixes in the query or dataset. For example, the local name of http://test.com/my#Example is Example.

Arguments:
  • resource () - The URI resource to get the local name of.
Returns: xsd:string

lower-case

URL: fn:lower-case 
Description: Returns a string which is the lower case equivalent of the argument.

Arguments:
  • text (xsd:string) - The input string.
Returns: xsd:string

matches

URL: fn:matches 
Description: Performs string pattern matching based on regular expressions.

Arguments:
  • text (xsd:string) - The string to search in.
  • pattern (xsd:string) - The pattern string.
  • args (xsd:string) - The (optional) arguments for the regular expression matcher.
Returns: xsd:boolean

max

URL: afn:max 
Description: Gets the max value of two numeric arguments.

Arguments:
  • num1 () - The first value to compare.
  • num2 () - The second value to compare.
Returns: rdfs:Literal

maxCardinality

URL: smf:maxCardinality 
Description: Gets the maximum cardinality of a property at a class. The function checks for locally defined owl:maxCardinality restrictions on the class or its superclasses. If none is found, it will check if the property is functional and, if so, return 1. Otherwise it will return null.

Arguments:
  • class (rdfs:Class) - The class to get the cardinality at.
  • property (rdf:Property) - The property to get the cardinality of.
Returns: xsd:int

min

URL: afn:min 
Description: Gets the min value of two numeric arguments.

Arguments:
  • num1 () - The first value to compare.
  • num2 () - The second value to compare.
Returns: rdfs:Literal

minCardinality

URL: smf:minCardinality 
Description: Gets the minimum cardinality of a property at a class. The function checks for locally defined owl:minCardinality restrictions on the class or its superclasses. If none is found, it will return null.

Arguments:
  • class (rdfs:Class) - The class to get the cardinality at.
  • property (rdf:Property) - The property to get the cardinality of.
Returns: xsd:int

name

URL: smf:name 
Description: Gets a human-readable string representation from an RDF node. If it's a literal, the function will return the literal's lexical text. If it's a resource the system will use the rdfs:label (if exists) or otherwise use the qname.

Arguments:
  • node () - The node that shall be rendered into a string.
Returns: xsd:string

namespace

URL: afn:namespace 
Description: Returns the namespace of a URI resource. Based on splitting the IRI, not on any prefixes in the query or dataset. For example, the namespace of http://test.com/my#Example is http://test.com/my#.

Arguments:
  • resource () - The URI resource to get the namespace of.
Returns: xsd:string

now

URL: afn:now 
Description: Gets the current time as xsd:dateTime. Actually, the time the query started. Constant throughout a query execution.

Arguments:
Returns: xsd:dateTime

parseDate

URL: smf:parseDate 
Description: Converts a string in a semi-structured format into a xsd:date, xsd:dateTime or xsd:time literal. The input string must be in a given template format, e.g. "yyyy.MM.dd G 'at' HH:mm:ss z" for strings such as 2001.07.04 AD at 12:08:56 PDT.

Arguments:
  • text (xsd:string) - The input text.
  • template (xsd:string) - The template of the input string. This must conform to the pattern language implemented by the Java SimpleDateFormat class (http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html).
Returns:

pi

URL: afn:pi 
Description: Returns the value of pi, as an xsd:double.

Arguments:
Returns: xsd:double

qname

URL: smf:qname 
Description: Gets the qname of a resource, using the defined namespace abbreviations. In contrast to the official specs, this function will drop the : character if it's the first character in the string. If the resource does not have a suitable prefix abbreviation, the function will return the URI wrapped by <...>.

Arguments:
  • resource () - The resource to get the qname of.
Returns: xsd:string

round

URL: fn:round 
Description: Returns the nearest integer value to the argument.

Arguments:
  • num () - The input value.
Returns: xsd:int

setLanguage

URL: smf:setLanguage 
Description: Creates a new string literal with a given language from an existing value. For example, smf:setLanguage("House", "en") becomes "House"@en.

Arguments:
  • text (xsd:string) - The text of the new literal.
  • language (xsd:string) - The language of the result literal. May be empty to delete any existing language.
Returns: rdfs:Literal

starts-with

URL: fn:starts-with 
Description: Test whether string starts with substr.

Arguments:
  • text (xsd:string) - The string to search in.
  • substr (xsd:string) - The substring to check for.
Returns: xsd:boolean

string-join

URL: fn:string-join 
Description: Returns the concatenation of string1 and string2.

Arguments:
  • string1 (xsd:string) - The first string.
  • string2 (xsd:string) - The second string.
Returns: xsd:string

string-length

URL: fn:string-length 
Description: Gets the length of a string (number of characters).

Arguments:
  • text (xsd:string) - The string to get the length of.
Returns: xsd:int

subString

URL: smf:subString 
Description: Extracts a substring from an input string. This is similar to afn:substr but more robust against null values.

Arguments:
  • text (xsd:string) - The input string.
  • startIndex (xsd:int) - The start index (0 is the first character). If not bound, then the function will return null.
  • endIndex (xsd:int) - The end index. If not bound, use the length of text - 1.
Returns: xsd:string

substr

URL: afn:substr 
Description: Extracts a substring, Java style using startIndex and endIndex.

Arguments:
  • text (xsd:string) - The input string.
  • startIndex (xsd:int) - The index of the first character to get the sub string from (0 is the first character).
  • endIndex (xsd:int) - The (optional) end index of the string to extract.
Returns: xsd:string

substring

URL: fn:substring 
Description: Returns the substring of a string, given by startIndex (integer) and, optionally, length length. Absence of length means to end of string. Strings are indexed from zero. Strings start from one, not zero as they do in Java and C#. 3rd argument is the length, like C# but unlike Java, where it is the endIndex.

Arguments:
  • text (xsd:string) - The string to operate on.
  • startIndex (xsd:int) - The index to start at (first character is 1).
  • length (xsd:int) - The (optional) number of characters to include in the substring.
Returns: xsd:string

titleCase

URL: smf:titleCase 
Description: Converts an input string to title case. For example, germany becomes Germany.

Arguments:
  • text (xsd:string) - The input string.
Returns: xsd:string

trim

URL: smf:trim 
Description: Creates a new string value by trimming an input string. Leading and trailing whitespaces are deleted.

Arguments:
  • text (xsd:string) - The text to trim.
Returns: xsd:string

upper-case

URL: fn:upper-case 
Description: Returns a string which is the upper case equivalent of the argument.

Arguments:
  • text (xsd:string) - The input string.
Returns: xsd:string