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 (JIRA)" <ji...@apache.org> on 2015/01/08 02:18:35 UTC
[jira] [Commented] (JENA-632) Generate JSON from SPARQL directly.
[ https://issues.apache.org/jira/browse/JENA-632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14268654#comment-14268654 ]
Bruno P. Kinoshita commented on JENA-632:
-----------------------------------------
Hello
The grammar has been [updated|https://github.com/kinow/jena/commit/ad17a099a1c5fb6577a02edc311ff8ceeaa08183#diff-a55ff4fd4c62d2b74b34605f07294920] and it now supports the following syntax:
{noformat}
JSON { "name": ?name } WHERE { ?name ?a ?b } LIMIT 3
{noformat}
The {{LOOKAHEAD(2)}} is no longer necessary, thanks to Andy's suggestion :-) and I now, after changing it, find JSON easier to understand and avoid mistakes than SELECT JSON.
{noformat}
[1] QueryUnit ::= Query
[2] Query ::= Prologue ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery | JsonQuery ) ValuesClause
[...] ...
{noformat}
Q1) Does that look correct?
I've debugged it, and found that, considering that this grammar is correct for what is proposed in this issue, the next step would be update {{SPARQL_Query#executeQuery()}}, and prepare the [JSON result|https://github.com/kinow/jena/blob/99ff26d52cdaaca4a4094c247a161349c9f500f4/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java#L328].
I'm temped to re-use what SPARQL_Query does when the query type is select, and simply replace the variable names by the ones provided by the user. i.e.
{noformat}
JSON { "name": ?abcde } WHERE { ?abcde ?a ?b }
{noformat}
In the example above, I'd replace the var "abcde" by "name" before serializing the result.
Q2) Does that sound like a good plan?
Talking about the serialization... in Fuseki, users define the serialization type (xml, text/plan, json, etc).
Q3) Should we enforce JSON when the user uses a JSON query? I think it is not necessary, maybe we can simply return the result set with the changed variables.
Q4) And finally, is it safe and correct to use the {{JSONOutput#format}} to return the result of the JSON query? I think the result will be similar to:
**query:**
{noformat}
JSON { "name": ?a } WHERE { ?a ?b ?c }
{noformat}
**result:**
{noformat}
{
"head": {
"vars": [ "name" ]
} ,
"results": {
"bindings": [
{
"name": { "type": "uri" , "value": "http://example.org/book/book5" }
} ,
{
"name": { "type": "uri" , "value": "http://example.org/book/book5" }
} ,
{
"name": { "type": "uri" , "value": "http://example.org/book/book3" }
}
]
}
}
{noformat}
Reading the old comments here and the post in the fist comment, I think maybe we should use something new (or add some new method somewhere) to return something close to:
{noformat}
{
"head": {
"vars": [ "name" ]
} ,
"results": {
"bindings": [
{
"name": "http://example.org/book/book5"
},
{
"name": "http://example.org/book/book5"
},
{
"name": "http://example.org/book/book3"
}
]
}
}
{noformat}
Thanks!
> Generate JSON from SPARQL directly.
> -----------------------------------
>
> Key: JENA-632
> URL: https://issues.apache.org/jira/browse/JENA-632
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ, Fuseki
> Reporter: Andy Seaborne
> Priority: Minor
> Labels: gsoc, java, javacc
>
> The capability to generate JSON directly from a SPARQL (or extended SPARQL) query would enable the creation of JSON data API over published linked data.
> This project would cover:
> # Design and publication of a design.
> # Refinement of design based on community feed
> # Implementation, including testing.
> # Refinement of implementation based on community feed
> Skills required: Java, some parser work, design and discussion with the user community, basic understanding of HTTP and content negotiation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)