HOWTO get only the direct rdf:type with SPARQL
My RDF graph describes a class hierarchy (rdfs:subClassOf) and some instances (rdf:type) of these classes. For a GUI treeview I need all the instances (leaves) and their direct type.
With reasoning I can query for all the instances (leaves) but get all the inferred super classes also. I need just the direct rdf:type. How can I SPARQL it?
A rdf:type rdfs:Class .
B rdfs:subClassOf A .
C rdfs:subClassOf B .
I1 rdf:type B .
I2 rdf:type C .
I3 rdf:type C .
SELECT * WHERE {
?s a A .
?s a ?t .
}
?s ?t
---- -----
I1 B
I2 C
I3 C
but I get also all the inferred statements. That's right but
I want to exclude it from the result:
I1 rdfs:Resource
I1 rdfs:Class
I2 rdfs:Resource
I2 rdfs:Class
I2 B
I3 rdfs:Resource
I3 rdfs:Class
I3 B