Property functions in SPARQL are properties that return results based on executing code rather than directly graph matching. Property functions, also referred to as "magic properties", differ from SPARQLMotion Functions in that multiple bindings can be returned. TopBraid Composer provides its own property functions to extend the functionality of SPARQL. The following sections describe property functions available in TopBraid Suite:
Note that in addition to these property functions, SPARQL also provides BIND/FILTER
functions. TopBraid Composer supports all functions implemented by Jena, plus several
additional ones. These are described in the SPARQLMotion
Functions Reference.
If you want to add your own property functions, you can use SPIN's support for magic properties to declare new functions without programming. If you are a Java programmer, you can also add your new property functions using the Jena API and TopBraid extension points.
The following functions are available for all TBS platforms.
This property function returns all resources in any basket.
(Experimental) This function binds variables for constructing an RDF list. It can be best used in a CONSTRUCT query. It is an experimental function, so it may work only in certain cases.
CONSTRUCT { kennedys:College owl:oneOf ?list . ?subList rdf:first ?element . ?subList rdf:rest ?rest . } WHERE { (?list ?subList ?element ?rest) tops:constructRDFList (?s rdf:type kennedys:College) . }
Known limitations: Only one variable in ?s ?p ?o should be unassigned, and the other two should be assigned. The property "rdf:type" should be used instead of "a" in the function.
This function binds variables for constructing a string list.
SELECT ?x WHERE { ?x tops:constructStringList (?s rdf:type kennedys:College true true ", " "\"") }
Known limitations: Only one variable in ?s ?p ?o should be unassigned, and the other two should be assigned. The property "rdf:type" should be used instead of "a" in the function.
If ?baseURI is bound, then the statements in the corresponding ontology are returned.
If ?baseURI is an unbound variable, then the base URI of the currently selected ontology is returned at ?baseURI as well as the statements in the corresponding ontology. (In SPARQLMotion, this case might behave differently)
If ?baseURI is not given, i.e. blank subject, then the statements in the current graph are returned.
SELECT ?subject ?predicate ?object WHERE { <http://topbraid.org/sparqlmotion> tops:definesStatements (?subject ?predicate ?object) }
The above query returns all statements defined in the ontology with the base URI http://topbraid.org/sparqlmotion.
SELECT ?baseURI ?subject ?predicate ?object WHERE { ?baseURI tops:definesStatements (?subject ?predicate ?object) }
The above query returns all statements defined in the currently selected ontology. The base URI of the ontology is also returned.
SELECT ?subject ?predicate ?object WHERE { () tops:definesStatements (?subject ?predicate ?object) }
The above query returns all statements defined in the current graph.
This function returns statements depending on the input resource. The dependency in this context means that the returned statements can only exist with the input resource. The input resource can be a URI resource or blank node.
SELECT * WHERE { (?s ?p ?o) tops:dependsOn kennedys:photo . }
Known limitation: This function should be used with more care in SPARQLMotion, as the SPARQLMotion script may not have included obvious default inferences like ?c rdfs:subClassOf owl:Thing, if ?c is not a subclass of any class. The user may need to add more SPARQLMotion modules to handle such corner cases before running this function.
This function can be used to traverse the files in the workspace. A typical use case of this is in conjunction with SPARQLMotion scripts to do batch processing of multiple files, where the exact names of the files are unknown.
?path tops:files ("/TBC/Examples" false)
?path tops:files ("/MyProject/MyFolder" true)
This property can be used to implement loops over a range of integer values.
?index tops:for (2 4)
This function binds the input arguments on the right to the variables on the left.
SELECT * WHERE { ?x tops:foreach (kennedys:Gender kennedys:College kennedys:Person kennedys:Profession) }
Iterates through all defined ranges for a given class/property pair, including handling of owl:unionOf ranges.
Gets a list of all properties that are "relevant" for a given class. This includes all properties with matching domains and the restricted properties.
Gets a list of all properties that are "relevant" for a given subject resource. This includes all properties that already have a value for the subject plus those with matching domains and the restricted properties.
Gets a list of all properties that are mentioned in some restriction relevant to a given class.
This function can be used to split a string into multiple sub-strings separated by a given regular expression.
?s tops:split ("AAA BB C " " ")
SELECT ?baseURI WHERE { (geotravel:Accommodation rdf:type owl:Class) tops:statementDefinedIn ?baseURI }
The above query returns the base URI of geotravel ontology.
Gets subjects that are connected to an object via a transitive property. For instance, find all resources that are directly or indirectly rdfs:subClassOf a given class. Both the subject and object must be bound when the function is called. This function has the advantage of having the transitive property as a variable, when compared to property paths.
SELECT * WHERE { ?cls tops:transitiveAssociation (rdfs:subClassOf owl:Thing) . }
The following functions are available for TopBraid Live only.
Gets data on current TopBraid Live sessions.
SELECT * WHERE { () <http://topbraidlive.org/functions#sessions> ( ?userName ?baseURI ?startTime ?recentTime ) }