Retrieve just root classes/classes with no asserted subclassof parent class - owl-api

Is there an easy way to retrieve just the root classes from an OWL ontology in OWLAPI? Here I mean named classes with no asserted parent class. Added complexity, trying not to use reasoner because ontologies are huge and reasoner is not completing in fast enough time (typically). Thanks as always!

Actually using a reasoner would make the task trivial because the only named class without a parent would be owl:Thing.
Jokes aside, you'd need to take all the classes in the ontology signature and, for each one, ensure it does not appear in a subclass axiom as subclass (or, if it does, that the class on the other side is owl:Thing.
The code would look like this:
OWLDataFactory df=OWLManager.getOWLDataFactory();
OWLClass thing=df.getOWLThing();
OWLOntology o = ...
o.classesInSignature()
// all asserted superclasses
.filter(c->o.subClassAxiomsForSubClass(c)
// skip owl:Thing
.filter(s->!thing.equals(s.getSuperClass()))
// only keep the ones with no superclass
.count()==0)
.forEach(System.out::println);
This example prints out the IRIs for those classes.

Related

Ontologies only built with classes and not class instances

I am wondering why public biomedical ontologies are often organized in such a way that there are no class instances and only classes? I understand it in a way that all instances are classes, but I do not understand what is the advantage or purpose of such modelling? Those classes have also only annotation properties. For example NCIT ontology: https://bioportal.bioontology.org/ontologies/NCIT/?p=summary.
I would appreciate if someone could provide me with an explanation what is the purpose of such model and if there is an advantage to a model where classes have class instances. I am definitively not an expert in the field and I only was working on modelling 'standard' ontologies with classes and their instances.
TLDR
The reason for preferring classes over individuals (or instances) is that classes allow for sophisticated reasoning which is used to infer classification hierarchies.
The longer answer
The semantics of OWL allows you to make the following type of statements:
ClassExpression1 is a subclass of ClassExpression2
PropertyExpression1 is a subproperty of PropertyExpression2
Individual c1 is an instance of Class1
Individual x is related to individual y via property1
Of these 4 options, (1) by far allows for the most sophistication. Intuitively it comes down to how much each of these allow you to express and the reasoning capability to derive inferences from those statements. To get an intuitive feel of this, using the OWL Direct Semantics, we can see what
ClassExpression1 and ClassExpression2 can be substituted with:
There no way that this expressivity can be achieved using individuals.
Individuals vs Classes
In your question you say that all instances (individuals) are classes. This is not exactly true. Rather, classes consists of instances or instances belong to classes. From a mathematical perspective classes are sets and individuals are members of a set.
Annotations in biomedical ontologies
These ontologies have a substantial (80%-90%) amount of annotations. However, they do have lots of logical axioms. You can see it for example when you look at http://purl.obolibrary.org/obo/NCIT_C12392 on the righthandside, if you scroll down to the bottom, you will see the axioms listed:

Inferring the existence of individuals using Protege

I am trying to infer the existence of individuals in Protege, and can use some help.
Consider the following ontology as the example scenario: Persons may be siblings. If they are siblings then they have at least one mutual/common parent.
I defined a class called "Person" with a subclass of "CommonParent". I define the "sibling" object property from one "Person" (Domain) to another "Person" (Ranges), and marked it as "Symmetric".
I created three individuals (Mike, Jerry, Suzie) and added two assertions about one being sibling to another. The reasoner (HermiT) correctly classified the individuals as persons and added missing sibling relations.
Now, what I want to do is to have the reasoner infer the existence of another (unnamed) entity being the "CommonParent" of each sibling pair (without me specifically asserting that there is such individual). Is this possible? How do I approach this?
Protege screenshot

OWL, adding a property to all instances of a class

I'm looking for a way to add an Object Property to all instances of a given class.
Example Problem:
Let's say I'd define three classes.
Religious_Person
Supreme_Being
Christian a subclass of Religious_Person.
Now I'd like to have an Object property "devotes" which has a domain of Religous_Person and a range of Supreme_Being.
I have three instances of Christian: Marck, Bob and Cathy.
I have one instance of Supreme_Being: God.
Now I'd like to state Marck devotes God, Bob devotes God, and Cathy devotes God. It seems tedious to do this for every instance, so I'd like to express that each instance of the class Christian devotes God by default. Now ofcourse this might be somewhat confusing as from this example it might seem that I'd want each and every Religious_Person to devote to only one Supreme_Being, which is not the case.
Example:
Let's say JackAndJillian is a Religious_Person that devotes both Jack and Jill. So I'd like each instance of JackAndJillian to devote both Jack and Jill (whom would both be instances of Supreme_Being).
It feels to me like "devotes" should be a object property of the class Christian, however this is not possible due to classes not having properties.
I'm using protege to help myself in building an ontology so if there'd be a way I can express this in protege that would be great.
You can use owl:hasValue in a SubClassOf axiom (in Manchester OWL syntax):
Class: Christian
SubClassOf: Religious_Person and devotes value God
There is no concept of default value in OWL. Inference in OWL is monotonic, thus, you cannot remove any statement by adding other statements.

Map classes of one ontology to individuals of another

I need to map classes from a preexisting ontology to individuals in mine. I'm looking for an elegant way to do so. For instance, let's say the preexisting ontology has:
Class Drug1 with subclasses Brand1, Brand2, Brand3
In my ontology, I want to have Brand1, Brand2, and Brand3 as individuals of Class Drug1.
I cannot use owl:sameAs because it is for individual-individual mapping. Similarly, I probably cannot use equivalentClass becuase it is for class-class mapping.
What is a good approach to take in such a scenario?
It's done by punning. In Protege, just have identical names for the class and the individual you'd like to pun.

Get TBox Axioms with OWL API

I'm working with a OWL API 3 / Pellet / SPARQL-DL stack and want to read the asserted TBox axioms of a certain class from an ontology.
I can easily access the axioms with OWL API. However, the OWLClassAxiom just provides function to access the signature without the connections. I.e. I want to know to which Class a ObjectProperty is assigned to. All I can retrieve is a set of all elements in the signature, without their connection.
It seems that OWL API does not really support working with given axioms on a class level well (Reading, not adding.) Or am I missing something? Any other ideas how to achieve that? (With whatever tools.)
Concrete Example: Pizza hasBase some PizzaTopping. I want to retrieve the value "PizzaTopping" by specifying Pizza and hasBase.
If Pizza is a class, then
Pizza hasBase some PizzaTopping
isn't a legal axiom. What you probably actually have is
Pizza subClassof hasBase some PizzaTopping
That means that every instance of Pizza is related to some instance of PizzaTopping by the hasBase property. The axiom is a subclass axiom, so you'd want to retrieve an instance of OWLSubClassOfAxiom, (which is a subclass of OWLClassAxiom).
In this case, if you have a reference to the OWLClass for Pizza, then you could use OWLClass#getSuperclasses() to get a list of superclass expressions. One of them would be an OWLObjectSomeValuesFrom expression for (hasBase some PizzaTopping). You'd have to look for the ones of that type, and then examine the property that it is a restriction on.
That said, your stated goal
to know to which Class a ObjectProperty is assigned to
doesn't quite match up with the OWL model. Object properties (and data properties) don't "belong" to classes in OWL. You can use subclass axioms and property restrictions, like above, to say that members of a class must have a value for a particular property,

Resources