Search code examples
sparqlrdfowl

Displaying results of a variable not common with another variable in SPARQL


I have an OWL file, which stores the triples Person-hasFriend-Person relations. The OWL file has information about 10 Persons and the only information it has is about hasFriend.

All persons have hasFriend relation with A and only five persons have hasFriend relation with B. Now, I want to query those five persons who have hasFriend relation only with A by a query which will display names of persons who do not have hasFriend relation with B. How can I implement this in SPARQL?

Here I am asking for an indirect way of displaying the names of persons who have hasFriend relation with A.


Solution

  • Yous should provide some details of your OWL file. However, if I understand well what you want, your query would look similar to this:

    select ?person where {
      ?person hasFriend A.
      FILTER (NOT EXISTS {?person hasFriend B})
    }