In a GraphDB custom ruleset, I need to access only the explicitly declared superclass of an element, but I can't find any predicate (like sesame:directSubClassOf
), nor use the implicit/explicit context (onto:explicit
/ onto:implicit
). Any workaround I've tried so far has failed.
To illustrate the issue, say I have the following triples:
:x :rdf:type :a.
:y :rdf:type :b.
:z :rdf:type :c.
:a rdfs:subClassOf :b.
:b rdfs:subClassOf :c.
Because of transitivity, after inference (I ignored reflexivity here):
:x :rdf:type :a.
:x :rdf:type :b.
:x :rdf:type :c.
:y :rdf:type :b.
:y :rdf:type :c.
:z :rdf:type :c.
:a rdfs:subClassOf :b.
:b rdfs:subClassOf :c.
:a rdfs:subClassOf :c.
With this custom rule:
Id: hasDirectLinkTo
c1 <rdfs:subClassOf> c2
i1 <rdf:type> c1
i2 <rdf:type> c2
-------------------------------
i1 <:hasdirectlinkto> i2
I obtain all the instances of c1
and its superclasses linked to all the instances of c2
and its superclasses, by the predicate :hasdirectlinkto
, while in this case, I don't want the superclasses. Here:
1. :x :hasdirectlinkto :y
2. :x :hasdirectlinkto :z
3. :y :hasdirectlinkto :z
Where I don't want to get line 2 :x :hasdirectlinkto :z
.
Any suggestion would be greatly appreciated, thanks!
Based on your inquiry, it appears the goal is not merely to retrieve explicit triples via SPARQL, but to have a custom ruleset that operates only on the directly asserted (explicit) subclass relationships. Unfortunately, GraphDB custom rulesets do not offer a mechanism to filter triples based on their explicit versus inferred context. In other words, while the SPARQL query below successfully isolates explicit rdfs:subClassOf
triples by targeting the <http://www.ontotext.com/explicit> graph, this approach cannot be replicated within a custom ruleset.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?sub ?super
FROM NAMED <http://www.ontotext.com/explicit>
WHERE {
GRAPH <http://www.ontotext.com/explicit> {
?sub rdfs:subClassOf ?super .
}
}
This query retrieves only the user-asserted subclass relationships (e.g., :a rdfs:subClassOf :b
and :b rdfs:subClassOf :c
) and excludes the transitive, inferred triple (:a rdfs:subClassOf :c
). However, the custom ruleset engine does not support filtering based on the explicit/implicit context. This means that any rule defined to match rdfs:subClassOf
will inherently operate over both explicit and inferred triples.