One query example:
select * {
?s1 <urn:p> ?o1
optional { ?s1 <urn:q> ?t1 }
?s2 <urn:r> ?o2
optional {
?s2 <urn:s> ?t2
filter(?t1 = ?t2)
}
One query example:
select * {
?s1 <urn:p> ?o1
optional { ?s1 <urn:q> ?t1 }
?s2 <urn:r> ?o2
optional {
?s2 <urn:s> ?t2
filter(?t1 = ?t2)
}
This query generates an RDF list from an RDF graph that is a linear path. To set up initial data:
stardog query test "insert data { :a :p :b . :b :p :c . :c :p :d }"
The list generation query:
construct {
?start rdf:first ?s ;
rdf:rest ?end .
This shows how one can pivot a SELECT result set in SPARQL to have columns which correspond to row values. The topic is hot in the SQL world so perhaps one day people will start wondering about it in SPARQL.
This query pivots the (type, number_of_instances) relation generated by the inner subquery.
It uses Stardog-specific functions (:set
and :index
) but it's probably not too hard to adapt group_concat
(just a little clumsier, left as an exercise for the reader :)
prefix : <tag:stardog:api:>
[ { | |
"@id" : { | |
"@id" : "http://api.stardog.com/Alice", | |
"http://api.stardog.com/supervises" : { | |
"@id" : "http://api.stardog.com/Bob" | |
} | |
}, | |
"http://api.stardog.com/endedAt" : [ { | |
"@type" : "http://www.w3.org/2001/XMLSchema#integer", | |
"@value" : "2015" |