- From: Lee Feigenbaum <feigenbl@us.ibm.com>
- Date: Sat, 7 Oct 2006 17:01:39 -0400
- To: conor325 <conor@the325project.org>
- Cc: public-rdf-dawg-comments@w3.org
- Message-ID: <OFE0136B20.3DD7A5AD-ON85257200.00722C10-85257200.007381E7@us.ibm.com>
>
> In the following:
>
> _:a ex:name "Robert" .
> _:a ex:name "Bobby" .
>
> select ?name
> where {?a ex:name ?name}
>
> should the JSON output have a binding per name assertion or gather
> the name values in one binding? - one binding is much easier to
> process. If the values are gathered, should the literals be in one
> array or an array of values? In other words:
>
> "bindings": [
> {
> "name": { "type": "literal" , "value": "Robert" }
> } ,
> {
> "name": { "type": "literal" , "value": "Bobby" }
> } ,
This is the correct serialization as per
http://www.w3.org/TR/2006/NOTE-rdf-sparql-json-res-20061004/#variable-binding-results
. The spec says:
"""
For "each Query Solution in the query results" a Query Solution Object --
that is, a JSON object -- is added to the bindings array
"""
This is in keeping with the SPARQL Query Results XML Format (see
http://www.w3.org/TR/rdf-sparql-XMLres/#results ).
If you are working with SPARQL results from JavaScript and are doing
queries such as this example where you wish to only deal with a simple
array of result values, you may be interested in the sparql.js JavaScript
library, which allows you to write code such as:
var sparqler = new SPARQL.Service("http://sparql.org/sparql");
...
var names = sparqler.selectValues("SELECT ?name WHERE { ?a ex:name ?name
}"); // names is a JS array
for (var i = 0; i < names.length; i++) {
var name = names[i];
// do something with name
}
You can download the sparql.js library at:
http://www.thefigtrees.net/lee/sw/sparql.js . Some more information on the
library and some more usage examples are at:
http://www.thefigtrees.net/lee/blog/2006/04/sparql_calendar_demo_a_sparql.html
.
Lee
> OR
>
> "bindings": [
> {
> "name": { "type": "literal" , "value": ["Bobby", "Robert"] }
> } ,
> OR
>
> "bindings": [
> {
> "name": [{ "type": "literal" , "value": "Bobby" }, { "type":
> "literal" , "value": "Robert" }]
> } ,
>
>
>
Received on Saturday, 7 October 2006 21:02:04 UTC