I need to write a SPARQL query to find a superclass/subclasses of a given class.
For example, given http://139.91.183.30:9090/RDF/VRP/Examples/Phenomenon.rdf RDFS vocabulary file, I want to find the superclass of 'AcousticWave' (which is 'Wave').
Similarly if user enters 'Wave', I want to get all sub classes of 'Wave' (which are 'AcousticWave', 'GravityWave', 'InternalWave' and Tide').
How would I write such SPARQL query?
The predicate used in
rdfs
for state sub/super class relationships isrdfs:subClassOf
. With that in mind you just need to write triple patterns in your SPARQL query that bind that predicate and the subject or object that you want to match ---AcousticWave
in your case.I hope that the following queries are self-explanatory.
for super classes ...
And for sub classes ...
If you want to retrieve the labels for every subclass of
ns:Wave
you would do something like ...If you need the transitive closure of sub/super classes then you have two options: