I have this RDF
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:com="http://www.example.com/com#">
<rdf:Description rdf:about="http://www.example.com/com#1">
<com:cities>
<rdf:Bag>
<rdf:li>A</rdf:li>
<rdf:li>B</rdf:li>
<rdf:li>D</rdf:li>
</rdf:Bag>
</com:cities>
<com:name>1</com:name>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.com/com#2">
<com:cities>
<rdf:Bag>
<rdf:li>C</rdf:li>
<rdf:li>B</rdf:li>
</rdf:Bag>
</com:cities>
<com:name>2</com:name>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.com/com#3">
<com:cities>
<rdf:Bag>
<rdf:li>C</rdf:li>
<rdf:li>B</rdf:li>
<rdf:li>D</rdf:li>
</rdf:Bag>
</com:cities>
<com:name>3</com:name>
</rdf:Description>
</rdf:RDF>
Using Sparql I need to get names of all objects, which contains city D (1 and 3). I can do something like this:
SELECT ?name
WHERE {
?a com:cities ?cities.
?cities rdf:_1 ?s.
FILTER(?s = "D")
?a com:name ?name.
}
but it will check only first element. I could make more queries, with rdf:_2, rdf:_3, ... and use UNION, but I don't know number of rdf:li in Bag. Is there something like rdf:all? Or some other solution to do this? Thanks
Use
rdfs:member
if your system supports it or filter on the property URI: