I am new to RDF / Sparql, so I apologize for any incorrect terminology, as well as for a rather scary example:
Given the following RDF dataset:
@prefix owl: <http://www.w3.org/2002/07/owl
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns
@prefix e: <http://www.example.com/
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
e:Freemason a owl:Class .
e:Civilian a owl:Class .
e:Marty a e:Freemason .
e:Eugene a e:Freemason .
e:Mike a e:Freemason .
e:Alan a e:Freemason .
e:Paul a e:Civilian .
e:Marty foaf:knows e:Eugene .
e:Eugene foaf:knows e:Mike .
e:Eugene foaf:knows e:Paul .
e:Paul foaf:knows e:Alan .
I am trying to identify friends of friends who e:Martyonly know through e:Freemason.
So:
- Marty knows Mike through Eugene, and they are all Masons, so that's fine.
- Marty knows Eugene, who has a Civil friend Paul. Paul has a freemason friend Alan. However, Marty has no "Masons only" path to Alan, so he should be excluded.
Here's my SPARQL query:
prefix e: <http://www.example.com/
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
{
<http://www.example.com/
?target a e:Freemason .
}
This returns:
http://www.example.com/
http://www.example.com/
http://www.example.com/
Alan is included here because he meets the criteria is-a-freemason.
How do I modify the query to exclude Alan?
source
share