I have two classes A
and B
and I want to assert that A
is relatedClass
B
.
I want to do it at a class level, at first I thought of creating an object property relatedClass
and adding that assertion. But I can only do that between individuals.
OWLObjectProperty related = dataFactory.getOWLObjectProperty(IOR + "#relatedClass");
OWLAxiom axiom = dataFactory.getOWLObjectPropertyAssertionAxiom(related, classA, classB);
This is incorrect because the method expects classA
and classB
to be individuals.
Is it possible to set relationships between classes? How is it done using the OWL API?
I'm following this pattern to transform a taxonomy and it says:
Assert that competence is relatedClass of performance
Where both competence
and performance
are classes.
Ok, so based on your answers and comments I've been trying to understand which relationship is the pattern talking about. But I'm at a loss.
Firstly, the meaning of related is the same that the meaning of skos:related
so it's very general:
The property skos:related is used to assert an associative link between two SKOS concepts.
It's is used when two concepts are related but one isn't a more general or specific concept of the other. Plus, it's a symmetric property. One example from my domain is that "Information Systems" is related to "Systems security" (but as you can see it's a very generic kind of relationship).
Here is the diagram that is included as part of the pattern:
And here is a (very blurry, but that's how it looks on the paper) version of the diagram for the example:
So what I'm getting from here is that it needs to be an ObjectProperty
and I have to set up the domain and range, but how does it work if:
ClassA related ClassB
ClassC related ClassD
How do I set the domain and range in that case? Or do you think I should have one per pair of related classes?
This cannot be achieved using the OWL API because OWL does not support it. In specific the OWL specification states
Object properties connect pairs of individuals.
Hence, object properties do not link classes of individuals but individuals. The best you can do is to say that if 2 individuals are linked via an object property, those individuals belong to specific classes, which can be achieved using domain and range restrictions. I.e.:
ObjectProperty: relatedClass
Domain: A
Range: B
Using the OWL API you will need to do something as follows:
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
IRI relatedClassPropertyIRI = IRI.create(ontologyIRI + "#relatedClass");
IRI aClassIRI = IRI.create(ontologyIRI + "#A");
IRI bClassIRI = IRI.create(ontologyIRI + "#B");
OWLObjectProperty relatedClassProperty = dataFactory.getOWLObjectProperty(relatedClassPropertyIRI);
OWLClass aClass = dataFactory.getOWLClass(aClassIRI);
OWLClass bClass = dataFactory.getOWLClass(bClassIRI);
dataFactory.getOWLObjectPropertyDomainAxiom(relatedClassProperty, aClass);
dataFactory.getOWLObjectPropertyRangeAxiom(relatedClassProperty, bClass);
If you now use a property assertion axiom like
OWLAxiom axiom = dataFactory.getOWLObjectPropertyAssertionAxiom(related, individualA, individualB);
the reasoner will infer that individualA
belongs to class A
and individualB
to class B
.
Update
To deal with multiple related classes you have to use the unions of the classes for the domain and range:
ObjectProperty: relatedClass
Domain: A or C
Range: B or D