Previous topic  Top  Next topic  Print this Topic
 

Extension Functions

 

Expressions might contain calls to extension functions. In OntoBroker those functions are provided by built-ins, available in the context of FILTER expressions:

Filter built-ins are mapped to functions with boolean return value. There is one limitation to this approach: If you need the boolean return value outside of boolean operations, e.g. as an argument for another function, you have to use a functional built-in (see next paragraph) returning an explicit boolean term. However, a built-in filter will be sufficient for filtering in most use cases. For example, you might want to write an filter built-in with signature "even/1" to check if the argument is an even number. Another example is the already existing ObjectLogic built-in contains/2 (with namespace obl:reserved:) which checks if a string is contained in another string. This built-in might be used to filter for triples with their object containing the word 'house':

PREFIX obl: <obl:reserved:>

SELECT * WHERE { ?s ?p ?o. FILTER (obl:contains(?o, "house") }

Functional (and relational) built-ins allow the returning of an arbitrary RDF term. Mapping in the SPARQL function space is based on one simple assumption: The last argument of the built-in will always be the return value. Therefore the last argument has to be omitted if the built-in is called as a function. For example, a function to return the distance between two geographic coordinates, represented as a user-defined data type with latitude and longitude as one literal, might have the function signature "geoDistance/2" (coordinate1, coordinate2). However, the associated OntoBroker built-in has to increase the arity by one to provide the return value: "geoDistance/3" (coordinate1, coordinate2, distance). An exemplary SPARQL query using this function to find all cities with distances larger than 2000 km:

PREFIX obl: <obl:reserved:>

PREFIX : <http://www.example.com/geo#>

SELECT * WHERE { ?city1 a :City; :location ?l1. ?city2 a :City; :location ?l2. FILTER (obl:geoDistance(?l1, ?l2) > 2000) }

Any other built-in type like aggregations or connectors cannot be used inside SPARQL expressions.

Out of the box there are several built-ins available for various operations (mathematical, strings, time etc.).