You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Bruno P. Kinoshita" <ki...@apache.org> on 2014/11/26 00:49:00 UTC

Valid JSON keys in SPARQL endpoint response for Describe queries

Hi all,
Yesterday I was lurking in #jena's channel as I often do, when a user posted that his query
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX res: <http://www.w3.org/2005/sparql-results#>describe * where  {?movie rdf:type dbpedia-owl:Film.?movie rdfs:label ?label.?movie rdfs:label ?movie_title.FILTER langMatches(lang(?movie_title), "EN") .filter regex( ?label, "Inglourious Basterds", "i").}
against DBpedia SPARQL endpoint was failing with
Exception in thread "main" com.hp.hpl.jena.sparql.resultset.ResultSetException: Expected only object keys [type, value, xml:lang, datatype] but encountered 'lang'

I got the same Exception in my Eclipse workspace. While debugging with jena-2.12.0, I found that the Exception occurred in this code in jena-arq JSONInput [1]
Now, what intrigued me, was that in JSONResultsKW [2], there are constants that are used to filter the keys returned in JSON, IIUC. When the error is raised, these possible values include "xml:lang", as in the W3C documentation. However, DBpedia Virtuoso seems to be using "lang" as the key, without the xml prefix [3].
Is it a bug in arq, is DBpedia endpoint not following the specification, or is the error somewhere else? Reading the W3C page it doesn't mention describe queries, so not sure if it doesn't apply for this kind o query. Replacing describe by select the query seems to works (didn't look what's happening with his filter).
Here's the code he used [4]
Thanks!
ps: sent it hours ago, but I couldn't find it in the archives so re-sending it now.
[1] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONInput.java#L266
[2] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONResultsKW.java#L23
[3] http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=PREFIX+dbpedia-owl%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0APREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+res%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2005%2Fsparql-results%23%3E%0D%0Adescribe+*+where++%7B%0D%0A%3Fmovie+rdf%3Atype+dbpedia-owl%3AFilm.%0D%0A%3Fmovie+rdfs%3Alabel+%3Flabel.%0D%0A%3Fmovie+rdfs%3Alabel+%3Fmovie_title.%0D%0AFILTER+langMatches%28lang%28%3Fmovie_title%29%2C+%22EN%22%29+.%0D%0Afilter+regex%28+%3Flabel%2C+%22Inglourious+Basterds%22%2C+%22i%22%29.%0D%0A%7D&format=application%2Fsparql-results%2Bjson&timeout=30000&debug=on
[4] http://rdf.pastebay.net/1531054

Re: Valid JSON keys in SPARQL endpoint response for Describe queries

Posted by "Bruno P. Kinoshita" <ki...@apache.org>.
The bad syntax was my mistake. I was editing his example in Eclipse, and while testing with SELECT instead of DESCRIBE as he suggested, I probably introduced that typo and forgot to put DESCRIBE back there.
Thanks for the detailed explanation Andy! :) 
Bruno
 
      From: Andy Seaborne <an...@apache.org>
 To: dev@jena.apache.org 
 Sent: Thursday, November 27, 2014 6:35 AM
 Subject: Re: Valid JSON keys in SPARQL endpoint response for Describe queries
   
On 27/11/14 02:02, Bruno P. Kinoshita wrote:
>
> Hello Andy!
>
> The more I learn, the more I realize how little I know :)

:-)

> I think his code's gist expired, but FWIW here is another gist from my local copy [1].
> Thank you!Bruno
> [1] https://gist.github.com/kinow/f36c7cf989a4ee1b5478

?? Bad syntax!

"selectan" not "select"

and it calls execSelect, not execDescribe.  May be that is why they 
force "format="

The original had "describe *", does not mention ?s ?p ?o and got back a 
result set with (?s, ?p, ?o) so it looks like the query was issued with 
the override: format=application/sparql-results+json so the far did do 
something plausible, although asking for a graph and setting "accept" to 
a result set format has a HTTP status code of 406. (How does the caller 
know it's (?s, ?p, ?o) otherwise?)

The default accept header for a model (CONSTRUCT or DESCRIBE)

text/turtle, application/n-triples, application/rdf+xml;q=0.9, 
application/turtle;q=0.8, application/x-turtle;q=0.8, text/rdf+n3;q=0.7, 
application/n3;q=0.6, text/n3;q=0.6, text/plain;q=0.5, */*;q=0.1

which does not mention JSON but does have */*.  The format= overrides that.

(note to selves - add JSON-LD, remove N3).



    Andy



   

Re: Valid JSON keys in SPARQL endpoint response for Describe queries

Posted by Andy Seaborne <an...@apache.org>.
On 27/11/14 02:02, Bruno P. Kinoshita wrote:
>
> Hello Andy!
>
> The more I learn, the more I realize how little I know :)

:-)

> I think his code's gist expired, but FWIW here is another gist from my local copy [1].
> Thank you!Bruno
> [1] https://gist.github.com/kinow/f36c7cf989a4ee1b5478

?? Bad syntax!

"selectan" not "select"

and it calls execSelect, not execDescribe.  May be that is why they 
force "format="

The original had "describe *", does not mention ?s ?p ?o and got back a 
result set with (?s, ?p, ?o) so it looks like the query was issued with 
the override: format=application/sparql-results+json so the far did do 
something plausible, although asking for a graph and setting "accept" to 
a result set format has a HTTP status code of 406. (How does the caller 
know it's (?s, ?p, ?o) otherwise?)

The default accept header for a model (CONSTRUCT or DESCRIBE)

text/turtle, application/n-triples, application/rdf+xml;q=0.9, 
application/turtle;q=0.8, application/x-turtle;q=0.8, text/rdf+n3;q=0.7, 
application/n3;q=0.6, text/n3;q=0.6, text/plain;q=0.5, */*;q=0.1

which does not mention JSON but does have */*.  The format= overrides that.

(note to selves - add JSON-LD, remove N3).

	Andy


Re: Valid JSON keys in SPARQL endpoint response for Describe queries

Posted by "Bruno P. Kinoshita" <ki...@apache.org>.
Hello Andy!

The more I learn, the more I realize how little I know :)
I think his code's gist expired, but FWIW here is another gist from my local copy [1]. 
Thank you!Bruno
[1] https://gist.github.com/kinow/f36c7cf989a4ee1b5478
 
      From: Andy Seaborne <an...@apache.org>
 To: dev@jena.apache.org 
 Sent: Wednesday, November 26, 2014 7:10 AM
 Subject: Re: Valid JSON keys in SPARQL endpoint response for Describe queries
   
On 25/11/14 23:49, Bruno P. Kinoshita wrote:
> Hi all,
> Yesterday I was lurking in #jena's channel as I often do, when a user posted that his query
> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX res: <http://www.w3.org/2005/sparql-results#>describe * where  {?movie rdf:type dbpedia-owl:Film.?movie rdfs:label ?label.?movie rdfs:label ?movie_title.FILTER langMatches(lang(?movie_title), "EN") .filter regex( ?label, "Inglourious Basterds", "i").}
> against DBpedia SPARQL endpoint was failing with
> Exception in thread "main" com.hp.hpl.jena.sparql.resultset.ResultSetException: Expected only object keys [type, value, xml:lang, datatype] but encountered 'lang'
>
> I got the same Exception in my Eclipse workspace. While debugging with jena-2.12.0, I found that the Exception occurred in this code in jena-arq JSONInput [1]
> Now, what intrigued me, was that in JSONResultsKW [2], there are constants that are used to filter the keys returned in JSON, IIUC. When the error is raised, these possible values include "xml:lang", as in the W3C documentation. However, DBpedia Virtuoso seems to be using "lang" as the key, without the xml prefix [3].
> Is it a bug in arq, is DBpedia endpoint not following the specification, or is the error somewhere else? Reading the W3C page it doesn't mention describe queries, so not sure if it doesn't apply for this kind o query. Replacing describe by select the query seems to works (didn't look what's happening with his filter).
> Here's the code he used [4]
> Thanks!
> ps: sent it hours ago, but I couldn't find it in the archives so re-sending it now.
> [1] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONInput.java#L266
> [2] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONResultsKW.java#L23
> [3] http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=PREFIX+dbpedia-owl%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0APREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+res%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2005%2Fsparql-results%23%3E%0D%0Adescribe+*+where++%7B%0D%0A%3Fmovie+rdf%3Atype+dbpedia-owl%3AFilm.%0D%0A%3Fmovie+rdfs%3Alabel+%3Flabel.%0D%0A%3Fmovie+rdfs%3Alabel+%3Fmovie_title.%0D%0AFILTER+langMatches%28lang%28%3Fmovie_title%29%2C+%22EN%22%29+.%0D%0Afilter+regex%28+%3Flabel%2C+%22Inglourious+Basterds%22%2C+%22i%22%29.%0D%0A%7D&format=application%2Fsparql-results%2Bjson&timeout=30000&debug=on
> [4] http://rdf.pastebay.net/1531054

(can't see that code)



[3] is a SPARQL Result set, for SELECT queries.  Format 
application/sparq-results+json.

The request is a DESCRIBE query, not a SELECT

The Virtuoso request has "format=application/sparql-results+json" 
Setting the Accept header has the same effect.

A DESCRIBE query is an RDF graph and conneg should be for any RDF graph 
format.  JSON-LD or RDF/JSON [A] being JSON possibilities for encoding 
an RDF graph in JSON.

ARQ expects a graph to a graph request (DESCRIBE, CONSTRUCT).  A result 
set is not a graph.

Virtuoso sends a result set of (s,p,o) rows not a graph but you don't 
know it's (s,p,o) from the response.  (Somewhat tricky because you have 
to open the results first.)  Looks like a virtuoso special.

Content negotiation should have generated a "406 Not Acceptable" - the 
request is not compatible with the resource.  418 is also acceptable.

    Andy


[A] Non standard but reasonably common
We have a copy of the documentation as the Talis site isn't available 
any more.

http://jena.apache.org/documentation/io/rdf-json.html


   

Re: Valid JSON keys in SPARQL endpoint response for Describe queries

Posted by Andy Seaborne <an...@apache.org>.
On 25/11/14 23:49, Bruno P. Kinoshita wrote:
> Hi all,
> Yesterday I was lurking in #jena's channel as I often do, when a user posted that his query
> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX res: <http://www.w3.org/2005/sparql-results#>describe * where  {?movie rdf:type dbpedia-owl:Film.?movie rdfs:label ?label.?movie rdfs:label ?movie_title.FILTER langMatches(lang(?movie_title), "EN") .filter regex( ?label, "Inglourious Basterds", "i").}
> against DBpedia SPARQL endpoint was failing with
> Exception in thread "main" com.hp.hpl.jena.sparql.resultset.ResultSetException: Expected only object keys [type, value, xml:lang, datatype] but encountered 'lang'
>
> I got the same Exception in my Eclipse workspace. While debugging with jena-2.12.0, I found that the Exception occurred in this code in jena-arq JSONInput [1]
> Now, what intrigued me, was that in JSONResultsKW [2], there are constants that are used to filter the keys returned in JSON, IIUC. When the error is raised, these possible values include "xml:lang", as in the W3C documentation. However, DBpedia Virtuoso seems to be using "lang" as the key, without the xml prefix [3].
> Is it a bug in arq, is DBpedia endpoint not following the specification, or is the error somewhere else? Reading the W3C page it doesn't mention describe queries, so not sure if it doesn't apply for this kind o query. Replacing describe by select the query seems to works (didn't look what's happening with his filter).
> Here's the code he used [4]
> Thanks!
> ps: sent it hours ago, but I couldn't find it in the archives so re-sending it now.
> [1] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONInput.java#L266
> [2] https://github.com/apache/jena/blob/6ed1c766e74861db3a2219f9e7eb84ecc1ea8ef0/jena-arq/src/main/java/com/hp/hpl/jena/sparql/resultset/JSONResultsKW.java#L23
> [3] http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=PREFIX+dbpedia-owl%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2F%3E%0D%0APREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+res%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2005%2Fsparql-results%23%3E%0D%0Adescribe+*+where++%7B%0D%0A%3Fmovie+rdf%3Atype+dbpedia-owl%3AFilm.%0D%0A%3Fmovie+rdfs%3Alabel+%3Flabel.%0D%0A%3Fmovie+rdfs%3Alabel+%3Fmovie_title.%0D%0AFILTER+langMatches%28lang%28%3Fmovie_title%29%2C+%22EN%22%29+.%0D%0Afilter+regex%28+%3Flabel%2C+%22Inglourious+Basterds%22%2C+%22i%22%29.%0D%0A%7D&format=application%2Fsparql-results%2Bjson&timeout=30000&debug=on
> [4] http://rdf.pastebay.net/1531054

(can't see that code)



[3] is a SPARQL Result set, for SELECT queries.  Format 
application/sparq-results+json.

The request is a DESCRIBE query, not a SELECT

The Virtuoso request has "format=application/sparql-results+json" 
Setting the Accept header has the same effect.

A DESCRIBE query is an RDF graph and conneg should be for any RDF graph 
format.  JSON-LD or RDF/JSON [A] being JSON possibilities for encoding 
an RDF graph in JSON.

ARQ expects a graph to a graph request (DESCRIBE, CONSTRUCT).  A result 
set is not a graph.

Virtuoso sends a result set of (s,p,o) rows not a graph but you don't 
know it's (s,p,o) from the response.  (Somewhat tricky because you have 
to open the results first.)  Looks like a virtuoso special.

Content negotiation should have generated a "406 Not Acceptable" - the 
request is not compatible with the resource.  418 is also acceptable.

	Andy


[A] Non standard but reasonably common
We have a copy of the documentation as the Talis site isn't available 
any more.

http://jena.apache.org/documentation/io/rdf-json.html