DEPRECATED: As of TopBraid 6.1 we no longer recommend using this feature. Its functionality has been replaced with an equivalent SHACL-JS implementation.
SPIN provides various mechanisms to define new SPARQL functions. In addition to the user-defined functions that wrap other SPARQL queries (as described in Understanding SPIN Functions), it is also possible to define new SPARQL function using JavaScript. When executed, these BIND/FILTER functions will call JavaScript code that may use any of the constructs provided by that rich iterative programming language.
In order to use JavaScript-based functions, you need to import the
SPINx namespace http://spinrdf.org/spinx. This is part of the
standard system ontologies of TopBraid. Once you have imported this,
you should see the properties spinx:javaScriptFile
and
spinx:javaScriptCode
.
Here is one mechanism to define your functions using an external .js file:
spin:Functions
, e.g. called my:squarespin:returnType
such as xsd:integer
or rdfs:Resource
spin:body
emptyspinx:javaScriptFile
, e.g. myFunctions.jsAnother mechanism can be used to define functions inline:
spin:Functions
, e.g. called my:squarespin:returnType
such as xsd:integer
or rdfs:Resource
spin:body
emptyspinx:javaScriptCode
, e.g. return arg1 * arg1;More information on this capability, including an example, can be found on the official SPINx web page.