Re: PROV vocabulary class

2018-01-08 Thread ajs6f
Not really, but it's not unheard of. See:

https://github.com/apache/jena/blob/master/jena-core/src/main/java/org/apache/jena/vocabulary/DC_11.java

The Model isn't public, but it is available from most of the public fields via 
RDFNode::getModel.

What can be done instead is not have a Model involved and instead use 
ResourceFactory.

ajs6f

> On Jan 7, 2018, at 8:09 PM, Adam Jacobs  wrote:
> 
> Is it a good idea to have a public mutable model?
> 
> 
> 
> 
> From: Cotton Franck 
> Sent: Sunday, January 7, 2018 11:47 AM
> To: dev@jena.apache.org
> Subject: RE:PROV vocabulary class
> 
> Hi Adam. Here: 
> https://gist.github.com/FranckCo/889d1f137dc412ceab214159a49375e2
> 
> Franck
> 
> De : ajs6f [aj...@apache.org]
> Envoyé : dimanche 7 janvier 2018 18:07
> À : dev@jena.apache.org
> Objet : Re: PROV vocabulary class
> 
> This list doesn't permit attachments. Can you please send your work as a PR 
> on Github, or failing that, as a gist or pastebin or the like?
> 
> Adam Soroka
> 
>> On Jan 7, 2018, at 12:00 PM, Cotton Franck  wrote:
>> 
>> Hello
>> 
>> For my own needs, I created this class corresponding to the W3C PROV 
>> vocabulary. It could fit in the org.apache.jena.vocabulary package. Please 
>> fill free to add the relevant license text, I don't claim any IP on the 
>> class.
>> 
>> Cheers
>> Franck
> 



Re: JsonLD @vocab

2018-01-08 Thread Andy Seaborne

https://github.com/jsonld-java/jsonld-java/issues

or for general JSON-LD:

public-linked-j...@w3.org

Andy

On 08/01/18 01:17, Adam Jacobs wrote:

Do you know where jsonld discussions are at?
I'm having trouble finding a mailing list.



From: Andy Seaborne 
Sent: Thursday, January 4, 2018 2:34 PM
To: dev@jena.apache.org
Subject: Re: JsonLD @vocab

Adam,

In the first instance, this seems like something to raise with the
jsonld-java team to find out if that is intentional. Could you open a
discussion issue there?

IIRC empty prefix and the base are mixed up in JSON-LD.

  Andy

On 04/01/18 03:34, Adam Jacobs wrote:

The @vocab prefix is dropped by Jena when parsing JsonLD.
An empty prefix is correctly translated into @vocab during serialization, but 
is lost during deserialization.
Below code demonstrates the point.

  public static void main(String... args) {
  String base = "http://www.ns.com/base/;;
  String prefix = "http://www.ns.com/prefix/;;

  Model m = ModelFactory.createDefaultModel();
  m.setNsPrefix("", base);
  m.setNsPrefix("prefix", prefix);

  m.add(m.createResource(base + "foo"), m.createProperty(prefix + "bar"), 
m.createResource(base + "baz"));
  String jsonLD = serializeJsonLD(m);
  System.out.println(jsonLD);

  InputStream in = new ByteArrayInputStream(jsonLD.getBytes());
  Model m2 = ModelFactory.createDefaultModel().read(in, null, "jsonld");
  System.out.println(serializeJsonLD(m2));
  }

  public static String serializeJsonLD(Model m) {
  OutputStream out = new ByteArrayOutputStream();
  m.write(out, "jsonld");
  return out.toString();
  }

  From what I can see, jsonld-java is intentionally ignoring the @vocab key at 
line 277 of Context.java.
  
https://github.com/jsonld-java/jsonld-java/blob/master/core/src/main/java/com/github/jsonldjava/core/Context.java

I'm not sure if this is a bug in jsonld-java, or intentional behavior from a 
jsonld perspective that Jena should work around e.g. in JsonLDReader?



[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114387
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-2.rq ---
@@ -0,0 +1,4 @@
+PREFIX js: 
--- End diff --

Ditto previous comment, is it really `http://jena/apache.org`, and not 
`jena.apache.org`?


---


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160112461
  
--- Diff: jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java 
---
@@ -67,6 +67,13 @@
 /** XML Schema namespace */
 public static final String XML_SCHEMA_NS = 
"http://www.w3.org/2001/XMLSchema#; ;
 
+/** The URI prefix that triggers JavaScript functions */ 
+public static final String JavaScriptURI = 
"http://jena/apache.org/ARQ/jsFunction#; ;
--- End diff --

Probably `jena.apache.org` instead of `jena/apache.org`?


> 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)


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114420
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-3.rq ---
@@ -0,0 +1,4 @@
+PREFIX js: 
--- End diff --

Ditto previous comment...


> 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)


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114318
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-1.rq ---
@@ -0,0 +1,4 @@
+PREFIX js: 
--- End diff --

Is it really `jena/apache.org` and not `jena.apache.org`?


---


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160113269
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/function/js/EnvJavaScript.java ---
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Paths;
+
+import javax.script.*;
+
+import org.apache.jena.atlas.io.IO;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.riot.RiotNotFoundException;
+import org.apache.jena.sparql.ARQConstants;
+import org.apache.jena.sparql.ARQException;
+import org.apache.jena.sparql.SystemARQ;
+import org.apache.jena.sparql.sse.builders.ExprBuildException;
+import org.apache.jena.sparql.util.Context;
+import org.apache.jena.sparql.util.Symbol;
+
+/** Environment for executing a JavaScript function.
+ * 
+ * Functions are loaded from the file named in context setting
+ * {@link EnvJavaScript#symJavaScriptLibFile}.
+ * 
+ * Function are loaded from a string value in context setting
+ * {@link EnvJavaScript#symJavaScriptLib}.
+ * 
+ * If both are present, the file named by {@code 
EnvJavaScript.symJavaScriptLibFile} is loaded
+ * then the string from {@code EnvJavaScript.symJavaScriptLib}.
+ */
--- End diff --

Worth mentioning the file is read with UTF-8 encoding, and not system 
default?


> 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)


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114675
  
--- Diff: 
jena-arq/src/test/java/org/apache/jena/sparql/function/js/TestNV.java ---
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.sse.SSE;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestNV {
+
+@Test public void nv_1() { test("'abc'"); }
+@Test public void nv_2() { test("true"); }
+@Test public void nv_3() { test("123"); }
+@Test public void nv_4() { test("123.5"); }
+
+// No conversion to JS - becomes an NV.
+@Test public void nv_5() { 
test("'2018-01-06T17:56:41.293+00:00'^^xsd:dateTime"); }
+@Test public void nv_6() { test(""); }
--- End diff --

URL is a bit strange in the test file (i.e. jena/apche.org instead of 
jena.apache.org) but if the test is passing then it' all good :)


> 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)


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160113539
  
--- Diff: jena-arq/src/main/java/org/apache/jena/sparql/function/js/NV.java 
---
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.expr.ExprEvalException;
+import org.apache.jena.sparql.expr.NodeValue;
+
+/**
+ * General representation of an {@link NodeValue} for JavaScript. 
Conversion is to native
+ * types where possible, otherwise {@code NV}. {@code NV.toString} of a 
URI returns the
+ * uri as a string so {@code NV} works naturally in Java/Nashorn. 
+ * 
+ * @see #fromNodeValue
+ * @see #toNodeValue
+ */
+
+public class NV implements RDFJS {
+//  Six data types that are primitives in JavaScript:
+//   Boolean
+//   Null
+//   Undefined
+//   Number
+//   String
+//   Symbol (new in ECMAScript 6; not in Nashorn/Java8).
+//   and Object
+
+private NodeValue nv;
+/** 
+ * Enable restoring integer from doubles.
+ */
+private final static boolean narrowDoubles = true;
+/**
+ * Map an ARQ {@link NodeValue} to java/Nashorn representation of a 
JavaScript object.
+ * Native JaavScript types supported are null, string, number and 
boolean.
--- End diff --

s/JaavScript/JavaScript


---


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160112200
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/function/js/FunctionJavaScript.java
 ---
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+import java.util.List;
+
+import javax.script.ScriptException;
+
+import org.apache.jena.sparql.expr.ExprEvalException;
+import org.apache.jena.sparql.expr.ExprList;
+import org.apache.jena.sparql.expr.ExprUndefFunction;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.function.FunctionBase;
+
+/**
+ * Javascript implemented SPARQL custom functions for ARQ. The JavaScript 
function is
+ * called with arguments which are mapped so that XSD strings, numbers and 
booleans become the
+ * equivalent native JavaScript object, and anything else becomes a {@link 
NV}, a
+ * JavaScript object providing access to the RDF features such as datatype.
+ * {@link NV#toString} returns a string so a function working with URIs 
can treat URIs as
+ * strings which is natural in JavaScript and aligned to
+ * https://github.com/rdfjs/representation-task-force/;
+ * >rdfjs/representation-task-force.
+ * 
+ * Functions are executed in {@link EnvJavaScript}. There is a global
+ * {@link EnvJavaScript} and it can also be set specifically for a query 
execution.
+ * See {@link EnvJavaScript} for details of configuration.
+ * 
+ * Note: there is an
+ * attempt to reconstruct the datatype of the result of the function into
+ * {@code xsd:integer} and {@code xsd:double}.
+ * 
+ * Functions that return null or undefined will resutl in a {@link 
ExprEvalException}.
--- End diff --

s/resutl/result


> 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)


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

2018-01-08 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on JENA-1461:
--

Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114457
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-4.rq ---
@@ -0,0 +1,9 @@
+PREFIX js: 
--- End diff --

Ditto


> 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)


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114420
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-3.rq ---
@@ -0,0 +1,4 @@
+PREFIX js: 
--- End diff --

Ditto previous comment...


---


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160112200
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/function/js/FunctionJavaScript.java
 ---
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+import java.util.List;
+
+import javax.script.ScriptException;
+
+import org.apache.jena.sparql.expr.ExprEvalException;
+import org.apache.jena.sparql.expr.ExprList;
+import org.apache.jena.sparql.expr.ExprUndefFunction;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.function.FunctionBase;
+
+/**
+ * Javascript implemented SPARQL custom functions for ARQ. The JavaScript 
function is
+ * called with arguments which are mapped so that XSD strings, numbers and 
booleans become the
+ * equivalent native JavaScript object, and anything else becomes a {@link 
NV}, a
+ * JavaScript object providing access to the RDF features such as datatype.
+ * {@link NV#toString} returns a string so a function working with URIs 
can treat URIs as
+ * strings which is natural in JavaScript and aligned to
+ * https://github.com/rdfjs/representation-task-force/;
+ * >rdfjs/representation-task-force.
+ * 
+ * Functions are executed in {@link EnvJavaScript}. There is a global
+ * {@link EnvJavaScript} and it can also be set specifically for a query 
execution.
+ * See {@link EnvJavaScript} for details of configuration.
+ * 
+ * Note: there is an
+ * attempt to reconstruct the datatype of the result of the function into
+ * {@code xsd:integer} and {@code xsd:double}.
+ * 
+ * Functions that return null or undefined will resutl in a {@link 
ExprEvalException}.
--- End diff --

s/resutl/result


---


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114675
  
--- Diff: 
jena-arq/src/test/java/org/apache/jena/sparql/function/js/TestNV.java ---
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.sse.SSE;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestNV {
+
+@Test public void nv_1() { test("'abc'"); }
+@Test public void nv_2() { test("true"); }
+@Test public void nv_3() { test("123"); }
+@Test public void nv_4() { test("123.5"); }
+
+// No conversion to JS - becomes an NV.
+@Test public void nv_5() { 
test("'2018-01-06T17:56:41.293+00:00'^^xsd:dateTime"); }
+@Test public void nv_6() { test(""); }
--- End diff --

URL is a bit strange in the test file (i.e. jena/apche.org instead of 
jena.apache.org) but if the test is passing then it' all good :)


---


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160114457
  
--- Diff: jena-arq/testing/ARQ/JS/js-query-4.rq ---
@@ -0,0 +1,9 @@
+PREFIX js: 
--- End diff --

Ditto


---


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160112461
  
--- Diff: jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java 
---
@@ -67,6 +67,13 @@
 /** XML Schema namespace */
 public static final String XML_SCHEMA_NS = 
"http://www.w3.org/2001/XMLSchema#; ;
 
+/** The URI prefix that triggers JavaScript functions */ 
+public static final String JavaScriptURI = 
"http://jena/apache.org/ARQ/jsFunction#; ;
--- End diff --

Probably `jena.apache.org` instead of `jena/apache.org`?


---


[GitHub] jena pull request #340: JENA-1461: JavaScript custom functions

2018-01-08 Thread kinow
Github user kinow commented on a diff in the pull request:

https://github.com/apache/jena/pull/340#discussion_r160113269
  
--- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/function/js/EnvJavaScript.java ---
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.function.js;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Paths;
+
+import javax.script.*;
+
+import org.apache.jena.atlas.io.IO;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.riot.RiotNotFoundException;
+import org.apache.jena.sparql.ARQConstants;
+import org.apache.jena.sparql.ARQException;
+import org.apache.jena.sparql.SystemARQ;
+import org.apache.jena.sparql.sse.builders.ExprBuildException;
+import org.apache.jena.sparql.util.Context;
+import org.apache.jena.sparql.util.Symbol;
+
+/** Environment for executing a JavaScript function.
+ * 
+ * Functions are loaded from the file named in context setting
+ * {@link EnvJavaScript#symJavaScriptLibFile}.
+ * 
+ * Function are loaded from a string value in context setting
+ * {@link EnvJavaScript#symJavaScriptLib}.
+ * 
+ * If both are present, the file named by {@code 
EnvJavaScript.symJavaScriptLibFile} is loaded
+ * then the string from {@code EnvJavaScript.symJavaScriptLib}.
+ */
--- End diff --

Worth mentioning the file is read with UTF-8 encoding, and not system 
default?


---