Filter RDF file using SPARQL

33 views Asked by At

I am quite new to SPARQL and not sure that I am using it correctly, but I would like to use it to filter the rdf file - produce rdf file that contains only the parts of the graph that meet some conditions.

Let's say I have some rdf file containing triples:

id1 <http://xx.com/address> ids1
id1 <http://xx.com/name> John
id1 <http://xx.com/surname> Doe

ids1 <http://xx.com/street> Steep
ids1 <http://xx.com/number> 32

id2 <http://xx.com/address> ids2
id2 <http://xx.com/name> John
id2 <http://xx.com/surname> Dow

ids2 <http://xx.com/street> Flat
ids2 <http://xx.com/number> 32

And I would want to use sparql to produce rdf file containing only the part for surname Doe:

id1 <http://xx.com/address>ids1
id1 <http://xx.com/name> John
id1 <http://xx.com/surname> Doe

ids1 <http://xx.com/street> Steep
ids1 <http://xx.com/number> 32

But the first attempt only produces the triples for Doe, but not the address:

PREFIX xx: <http://xx.com/>

CONSTRUCT {
   ?s ?p ?o
}
WHERE {
     ?s ?p ?o .
     ?s xx:surname ?surname .
  FILTER(?surname = 'Doe')
}

Could you please tell me, what should I add to include also the subnodes and the parent nodes of those which fulfil the condition?

0

There are 0 answers