0

I want to find out the superclasses of a subclass but filter out all the superclass after finding a specific class. For example, this tree (from this question):

Main
   |__ Network
   |         |__ ATM
   |         |__ ARPANET
   |
   |__ Software
              |__ Linux
              |__ Windows
                        |__ XP
                        |__ Win7
                        |__ Win8

I want to find the superclasses for win7, but left out all superclasses above "Software" class:

Software
       |__ Windows
                 |__ Win7

This is the first thing I did:

SELECT ?superClass 
WHERE {
   :Win7 rdfs:subClassOf ?superClass .
   FILTER (?superClass != :Software)
}

But only left out :Software, and I want to filter our all other superclasses

  • first, you have to use property paths to navigate the hierarchy upwards starting from `:Win7`, or not? And then you have multiple options. For example, you could use `MINUS` and remove all transitive superclasses above `:Software` which you get by basically the same graph pattern just with the different start node. – UninformedUser May 22 '19 at 03:09
  • Which superclasses do you want to remove? In your example, Win7 has three: Windows, Software and Main. It looks like you want to keep two: Windows and Software. But then you say that removing Main is not enough, and you also want to remove “all other” superclasses. What other superclasses? Also, subClassOf is supposed to be in the `rdfs:` namespace but you have it in `rdf:` – cygri May 22 '19 at 05:54
  • @AKSW _first, you have to use property paths to navigate the hierarchy upwards starting from :Win7, or not?_ Yes, that's what I'm asking with "a specific class" in this case :WIn7. I'm going to check MINUS and update the question, but yes what I want as result from the query is just the superclasses of :Win7 and left out the superclasses above :Software – Incubus_inside May 22 '19 at 20:02
  • @cygri sorry for the confusion I modified my code, but I want to left out ALL superclasses above :Software, in this case :Main. But if the tree were to be more extense (:Main having superclass :SuperMain) this other superclasses should be filter out too. – Incubus_inside May 22 '19 at 20:05

1 Answers1

2

Most direct way is to use prperty paths and FILTER NOT EXISTS to exclude everything above :Software e.g.:

select * where { 
    :Win7 rdfs:subClassOf+ ?super .
    filter not exists {
        :Software rdfs:subClassOf+ ?super
    }
} 
Damyan Ognyanov
  • 791
  • 3
  • 7