Re: json-ld and sparql

On 3/15/16 9:33 AM, Jean-Claude Moissinac wrote:
> I'm trying to find best practices in the use of a json output from a
> sparql endpoint
> For exemple the request on dbpedia :
> prefix schema: <http://schema.org/>
> select distinct ?p ?name ?lat ?lon where {
> ?p a schema:Place .
> ?p rdfs:label ?name .
> ?p geo:lat ?lat .
> ?p geo:long ?lon .
> } LIMIT 5
> give me as json output
> { "head": { "link": [], "vars": ["p", "name", "lat", "lon"] },
>   "results": { "distinct": false, "ordered": true, "bindings": [
>     { "p": { "type": "uri", "value": "http://dbpedia.org/resource/Cameron_Parish,_Louisiana" } , "name": { "type": "literal", "xml:lang": "en", "value": "Cameron Parish, Louisiana" } , "lat": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#float", "value": "29.85" } , "lon": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#float", "value": "-93.2" }},
>     { "p": { "type": "uri", "value": "http://dbpedia.org/resource/Cameron_Parish,_Louisiana" } , "name": { "type": "literal", "xml:lang": "ar", "value": "\u0645\u0642\u0627\u0637\u0639\u0629 \u0643\u0627\u0645\u064A\u0631\u0648\u0646 (\u0644\u0648\u064A\u0632\u064A\u0627\u0646\u0627)" } , "lat": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#float", "value": "29.85" } , "lon": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#float", "value": "-93.2" }},
> ... < cut for clarity >
>  }} ] } }
> We loose the fact that ?p is a Place. We can factorize the 'type' on
> the table of results. And finally get a table of objects like thos one
> {
>     "p ":  "http://dbpedia.org/resource/Cameron_Parish,_Louisiana",
> "name": "Cameron Parish, Louisiana",
> "pos": { "lat": 29.85, "long": 93.2 }
> }
> I suppose some results can be obtained by using a context and some
> others by framing.
> Can we point me on ideas for clarification?
> Many thanks in advance
> --
> Jean-Claude Moissinac

Hi Jean-Claude,


Given the URI for Turtle doc returned from a DESCRIBE (as opposed to
SELECT) query :
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=prefix+schema%3A+%3Chttp%3A%2F%2Fschema.org%2F%3E%0D%0Adescribe++%3Fp++where+%7B%0D%0A%3Fp+a+schema%3APlace+.%0D%0A%3Fp+rdfs%3Alabel+%3Fname+.%0D%0A%3Fp+geo%3Alat+%3Flat+.%0D%0A%3Fp+geo%3Along+%3Flon+.%0D%0A%7D+LIMIT+5&format=text%2Fturtle&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on

You simply change the &format parameter value to produce this JSON-LD
document:
 
curl -i
"http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=prefix+schema%3A+%3Chttp%3A%2F%2Fschema.org%2F%3E%0D%0Adescribe++%3Fp++where+%7B%0D%0A%3Fp+a+schema%3APlace+.%0D%0A%3Fp+rdfs%3Alabel+%3Fname+.%0D%0A%3Fp+geo%3Alat+%3Flat+.%0D%0A%3Fp+geo%3Along+%3Flon+.%0D%0A%7D+LIMIT+5&format=application%2Fld%2Bjson&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on"

-- 
Regards,

Kingsley Idehen       
Founder & CEO 
OpenLink Software     
Company Web: http://www.openlinksw.com
Personal Weblog 1: http://kidehen.blogspot.com
Personal Weblog 2: http://www.openlinksw.com/blog/~kidehen
Twitter Profile: https://twitter.com/kidehen
Google+ Profile: https://plus.google.com/+KingsleyIdehen/about
LinkedIn Profile: http://www.linkedin.com/in/kidehen
Personal WebID: http://kingsley.idehen.net/dataspace/person/kidehen#this

Received on Tuesday, 15 March 2016 15:49:50 UTC