You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Andy Seaborne (JIRA)" <ji...@apache.org> on 2018/01/07 12:24:00 UTC

[jira] [Commented] (JENA-1461) Allow ARQ custom functions to be written in JavaScript

    [ https://issues.apache.org/jira/browse/JENA-1461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16315213#comment-16315213 ] 

Andy Seaborne commented on JENA-1461:
-------------------------------------

Having javascript functions is intended to give extensibility without requiring java, whether programming or classpath changes. Both testing (FILTER) and formatting results (AS) are important use cases.

*JavaScript loading*

Two context symbols:

* {{arq:js-library}} names a file to be loaded and compiled.
* {{arq:js-functions}} gives a string to be compiled.

*Function Naming*

The URI prefix "http://jena.apache.org/ARQ/jsFunction#" causes the local name to be used as the function name. This means there isn't a explicit registration process.

Using a prefix of {{PREFIX js:}} will make function calls look like:
{noformat}
PREFIX js: <http://jena/apache.org/ARQ/jsFunction#>

    js:appFunction(1,2,"foo",true)

{noformat}

*Arguments and Results*

ARQ expression evaluation works from values of {{NodeValue}}. Rather than pass raw {{NodeValue}}'s to
the JavaScript function or pass in RDF Terms ({{Node}}), the proposal is to map an {{xsd:string}} to a JavaScript string, an {{xsd:boolean}} to a JavaScript boolean and XSD numbers to JavaScript numbers.  Anything else gets wrapped in an {{NV}}, e.g. {{xsd:dateTime}}.

The reverse process is applied to function results, by introspecting on the class of the returned object. For numbers, there is also an attempt to convert JavaScript return Java Double to an {{xsd:integer}} by looking at the value.

*NV*

{{NV.toString}} is the same as the SPARQL {{STR}} function.

There are various getters, 

{noformat}
  public String getLabel()
  public String getDatatype()
  public String getLang()
  public String getLex()
  public String getUri()
{noformat}

so {{nv.lang}} works (Nashorn maps field access to getters by reflection).

To align with [RDFJS|https://github.com/rdfjs/representation-task-force/">rdfjs/representation-task-force]

{noformat}
  public String getTermType()
  public String getValue()
{noformat}


> Allow ARQ custom functions to be written in JavaScript
> ------------------------------------------------------
>
>                 Key: JENA-1461
>                 URL: https://issues.apache.org/jira/browse/JENA-1461
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: ARQ
>    Affects Versions: Jena 3.6.0
>            Reporter: Andy Seaborne
>            Assignee: Andy Seaborne
>
> Provide execution of JavaScript for SPARQL extension functions.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)