Consider the following instance of SomeClass
:
instances:some_thing1
a semapi:SomeClass ;
semapi:hasChainTo (
[ ... ] [ ... ] [ ... ]
) .
I need every instance (some_thing2
, some_thing3
, etc.) to have its hasChainTo
property point at the same list of blank nodes (as in there is only one copy of it). I need to maintain the list of blank nodes syntax because the chains get very deep and this syntax is very fluid for writing out each chain (for SomeClass2
, SomeClass3
, etc.).
If I simply make a base class and subClassOf from it, the hasChainTo
property inherits but not the object it's pointing to. This intuitively makes sense but I need the other behavior.
How can this be accomplished?
If you want to refer to the same thing from multiple nodes in the graph, you should give it a URI. It doesn't have to be a full http:
URI - you could use a UUID:
instances:some_thing_1
semapi:hasChainTo <urn:uuid:12345>.
instances:some_thing_2
semapi:hasChainTo <urn:uuid:12345>.
instances:some_thing_3
semapi:hasChainTo <urn:uuid:12345>.
<urn:uuid:12345>
semapi:chain (
[ .. ] [ .. ] [ .. ]
).
Don't confuse RDFS/OWL sub-classes with inheritance of state and behaviour in object-oriented languages. The class hierarchy in RDFS is for classifying nodes - i.e. assigning them to a class, where a class is some set of resources. There is no direct equivalent of the code-reuse you get from inheritance in languages like Java.
You're probably working in RDF(S), and not in OWL, but if you do have the ability to use OWL based tools, and for the sake of anyone who finds this question and can use OWL based tools, here's an OWL-based answer.
If you want every instance of a class (including instances of its subclasses) to have some property value in common, you can use an Individual Value Restriction. In the Manchester syntax, you can say that instances of SomeClass
all have the value sharedIndividual
for the propery hasValue
by the axiom:
SomeClass SubClassOf hasValue value sharedIndividual
Then every instance of SomeClass
has the type hasValue value sharedIndividual
, which means that the instance has sharedIndividual
as a value for the hasValue
property.
Here's the N3 serialization of an ontology with a class SomeClass
and two subclasses SomeSubClass
and AnotherSubClass
. Each of the three classes has a declared individual. The type hasValue value sharedIndividual
is a superclass of SomeClass
.
@prefix : <http://www.example.com/valueClassExample#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://www.example.com/valueClassExample>
a owl:Ontology .
:hasValue
a owl:ObjectProperty .
:sharedValue
a owl:Thing , owl:NamedIndividual .
:SomeClass
a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:hasValue :sharedValue ;
owl:onProperty :hasValue
] .
:SomeSubClass
a owl:Class ;
rdfs:subClassOf :SomeClass .
:AnotherSubClass
a owl:Class ;
rdfs:subClassOf :SomeClass .
:SomeClassInstance
a :SomeClass , owl:NamedIndividual .
:SomeSubClassInstance
a owl:NamedIndividual , :SomeSubClass .
:AnotherSubClassInstance
a owl:NamedIndividual , :AnotherSubClass .
With this ontology loaded in Protégé and with Pellet attached for reasoning, asking which individuals have sharedValue
as a value of the hasValue
property shows all the individuals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With