sparql.anything
sparql.anything copied to clipboard
Injecting code dynamically within the SPARQL query for manipulating data
We can use for example a python interpreter for running the code
I think Apache Jena's value functions are pretty convenient. I used that feature here.
Do you have in mind something like the following?
select * where {
fx:properties fx:location "https://sparql-anything.cc/example1.json" .
?s ?p ?o .
fx:properties fx:custom-code "filter(lambda x: x not in 'aeiou', o)"
}
Assuming variables bound in SPARQL get passed to the python environment.
Might not be too much to implement with something like: https://www.jython.org/
A custom magic property approach could be expanded to also pass parameters to Python functions, returning data can then be expressed as Facade-X. In other words, one could use the external component as an intermediate processor of the data source.
E.g. JSON File > Python function (returns any Python object) > Facade-X representation to be queried in the service clause.
This may require the development of a small vocabulary:
- Support inline lambdas/functions
- Refer to an external source code/function
- Pass parameters to the function
Apparently, APache Pig uses Jython for the same reason (custom functions): https://pig.apache.org/docs/r0.17.0/udf.html#jython-udfs
Note that Jython currently only supports Python 2.7 (Python 3.8 is under development but without a clear timeline: https://github.com/jython/jython/issues/24#issuecomment-670022103)
Another project to look into is GraalVM for Python https://github.com/oracle/graalpython/blob/master/docs/user/Jython.md
Maybe there is value in considering supporting script invocation (e.g. via a SH terminal) with the assumption that STDOUT shall return any of the supported SPARQL Anything formats.
I am not sure where we want to go with this one.
- Jena has a number of convenient ways to extend the library of functions (e.g. using Javascript)
- Is there a use case that cannot be easily developed with just sending the data to an external script with the
fx:command
option?