


Notice how all of the JavaScript function calls in the SPARQL query have a js: prefix that is declared at the top like any other prefix. Calls a JavaScript Date() function directly (as opposed to calling it via something in myjs.js) and assigns the returned value to an ?updateDate variable that also gets used in the CONSTRUCT clause.Calls the createRating() function in the same JavaScript file and passes the result to the CONSTRUCT clause, which puts the generated value in a d:rating triple.Passes the v:homeTel value to a normalizeUSPhoneNumber() function that I wrote in the myjs.js file.The query in jstest.rq copies the triples and also does the following: The v:homeTel values use several different conventions for notating US phone numbers: v: d. The data file that I used for my experiments simply lists a few people and their phone numbers. It’s basically a typical invocation of arq with an additional -set parameter to point at a file of JavaScript functions, which in this example is called myjs.js: arq -set arq:js-library=myjs.js -query jstest.rq -data phoneNumbers.ttl I had some fun playing with this capability, and as you’ll see, it offers some easy opportunities to clean up and improve your data.įirst, let’s see how it looks on the command line to run arq with a SPARQL query that calls external JavaScript functions.
Arq set how to#
The ARQ - JavaScript SPARQL Functions page of the Jena documentation shows how to do this.

When I saw “Add support for scripting languages other than JavaScript” in the Jena release 4.0.0 release notes my first reaction was “What? I can run the arq command line SPARQL processor and call my own functions that I wrote in JavaScript?”
