w3c / sparql-dev

SPARQL dev Community Group
https://w3c.github.io/sparql-dev/
Other
121 stars 19 forks source link

Dynamic function invocation #20

Open rvesse opened 5 years ago

rvesse commented 5 years ago

Why?

Currently SPARQL has a fairly robust extension function mechanism that allows for arbitrary functions to be referred to by URIs. This allows for vendors to implement useful extensions and for those to be even interoperable if vendors publish definitions of the semantics of their functions, since then other vendors can also add implementations associated with the same URI.

However there is no way currently to do dynamic function invocation i.e. cases where you want to run different functions based on some conditions. The best you can do currently is to use IF to select different functions, which are known in advance, to evaluate based on some conditions e.g.

BIND(IF(?x > 0, ex:a(?x), ex:b(?x)) AS ?z)

This doesn't cover the use case of data driven function selection e.g. where the data itself encodes the desired function. So the following is currently illegal:

BIND(?x(?y) AS ?z)

Existing Solutions

Apache Jena currently supports dynamic function invocation by introducing a new built-in function called CALL() in it's ARQ syntax:

BIND(CALL(?x, ?y) AS ?z)

This is a n-ary function i.e. it can take any number of arguments. It's semantics are defined as follows:

jindrichmynarz commented 5 years ago

How would you select the function to run if not via if()? VALUES or determining the function IRI by pattern matching in data describing the functions? In other words, it would help me to understand the issue if there were examples of using the dynamic function invocation.

cygri commented 5 years ago

In TopQuadrant we have used the call function as provided by ARQ to check lexical forms against a datatype in a generic way:

BIND (call(?datatypeIRI, ?lexicalForm) AS ?literal)

If bound(?literal) returns true, then the lexical form is valid for that datatype. This makes use of the fact that datatype constructor functions return an error for invalid lexical forms. Only works for supported datatypes, of course.

zacharywhitley commented 5 years ago

This sounds similar to what was proposed by Maurizio Atzori in "Toward the Web of Functions: Interoperable Higher-Order Functions in SPARQL" It outlined more than what is being discussed here but it included something like a CALL() function

VladimirAlexiev commented 5 years ago

These are related: