3

I am doing some testing on Stardog data retrieval and I am not sure how to address the following:

I have a Stardog database that I query via HTTP URL (http://localhost:5820/myDB/query?query=...) and Accept = "application/sparql-results+json"

I have created a SPARQL query that looks like this:

select distinct ?p ?childname 
where { 
    ?p a ex:Person . 
        OPTIONAL { ?p ex:hasChild ?child .
        ?child rdfs:label ?childname . }
}

My problem is that this gives me one object per child, like (note the notation is illustrative):

{ p = XXX
childname = AAA
}
{ p = XXX
childname = BBB
}
....

I can "solve" this with a GROUP_CONCAT but this will just concatenate strings:

{ p = XXX
childname = AAA, BBB, ....
}

I need to obtain the proper JSON structure:

{ p = XXX
   { childname = AAA }
   { childname = BBB }
 .....
}

I could of course run two SPARQL queries, one to obtain ?p and another one to obtain the list of ?childname, but this is actually not possible in my situation (without entering in details about why not).

How can I obtain these results with a single URL in JSON?

Anderson
  • 138
  • 7
Jiron
  • 31
  • 1
  • 1
    The result of this query is a sequence of bindings, and each binding will have a value for p, and optionally a value for childname. You can use group by, as you note, but you'll have to combine those values; you won't be able to get them in the format that you want. You'll have to postprocess your results. – Joshua Taylor Jul 15 '14 at 22:41

1 Answers1

0

Results in JSON-LD is probably the closest you can get to the desired format without postprocessing. You will need to rewrite the query into CONSTRUCT, and use Accept: application/ld+json.

marat
  • 1,247
  • 9
  • 14