Get the ontology classes by hierarchical levels - owl

I wanna get ontology classes but not in a randomly way, I'm looking for a way to get them by their hierarchical levels: I mean showing for each level of the ontology its classes; is it possible, knowing that I'm using OWL API.

OWLDataFactory df = OWLManager.getOWLDataFactory();
OWLReasoner reasoner = ...
NodeSet<OWLClass> subClasses = reasoner.getSubClasses(df.getOWLThing(), true);
subClasses will contain the set of direct subclasses of owl:Thing - i.e., the classes one level below owl:Thing. From there, you can apply the same call for each entity in the NodeSet to visit the class graph. You'll of course need an OWLReasoner implementation to create the reasoner object.

Related

Sulu CMF - CRUD Filtered Multi-Item-Selection for association entities

I have three entities:
class DataSet {
string $name;
Collection $points; // List<DataPoint>
Collection $groups; // List<DataGroup>
}
class DataGroup {
string $name;
Collection $assignedPoints; // List<DataGroupPoint>
}
class DataPoint {
string $name;
Collection $assignedGroups; // List<DataGroupPoint>
}
class DataGroupPoint {
DataGroup $group;
DataPoint $point;
int $data;
}
I extended the Admin UI to perform CRUD operations on the DataSet entity, as per docs. By looking at the ContactBundle Javascript extension, I was able to add CRUD operations for DataPoint entities within the DataSet form by registering a CardCollection - works fine.
Now, I want to perform CRUD operations on associated DataGroup entities of the DataSet as well - for that I want to put a MultiItemSelection component into the DataGroup overlay form in order to add, edit or remove DataGroupPoints.
For a DataGroupPoint entity, both the DataGroup and the DataPoint are supposed to belong to the same DataSet (which in turn is being edited in the overall form).
How can I provide all matching DataPoint entities to the MultiItemSelection?
As far as I understand your question, you are looking for a custom data_point_selection content type.
To achieve this I can recommend you to take a look at the Sulu Workshop, especially assignment 11. In this assignment a single_location_selection is implemented. This is a selection for the custom entity location.
Another great example for a custom selection or single_selection is the example pull request of the sulu demo.
As a side note, the implementation of the ContactBundle is very specific for this case. Therefore the extendability and usability of the used components like CardCollection is not the best. For a better developer experience I would recommend you to stick to the documented content types in the docs. Unless you really need these specific components.

how to join equivalent classes from 2 different ontologies in Protegé?

I'm new in Protegé. I've created a new Ontology and I would like to merge the Person class with Person class in foaf.
How can I do that? I have tried with Equivalent to but I don't see both ontologies linked in http://www.visualdataweb.de/webvowl
Foaf and mine ontologies separated
I found the solution. I realized that Person class in my ontology is a subclass in foaf antology.
So, I've added as a subclass in Protegé and it worked :)

Getting the number of individuals in ontology with OWL API

How can I get the number of individuals in ontology regardless to the classes or subclasses they belong to, only by using OWL API (not SPARQL or other tools).
I was trying this:
NodeSet<OWLNamedIndividual> inds = reasoner.getInstances(subClass, false);
int numofInd = inds.getNodes().size();
Where subClass is a subclass of Thing. But how could I get the whole number of individuals in ontology.
OWLOntology::getIndividualsInSignature(boolean includeImportsClosure) returns all individuals including the imports closure, see the Javadocs

OWL: How to get inheritance of property relations between two classes from those of superclasses?

Let's say we have two classes named People and Disease. These classes are related by the Object Property has.
:People :has :Disease
People has subclass (or individual) John, and Disease has subclass (or individual) Cancer.
:John a :People
:Cancer a :Disease
How can we get the relationship between these subclasses by inference?
:John :has :Cancer
Before you can get to an answer, there are a number of misconceptions you'll need to resolve.
First, subclass and individual are very different concepts. Individuals (instances) are members of classes. Subclass denotes a class is a subset of another class, meaning that an implication (via inference) is that all members of a subclass are members of the (super)class. (Just for reference: there is no concept of inheritance in OWL.)
Second class-level properties, such as :People :has :Disease have no meaning for class individuals. The way to define a property's relationships to classes is to set the domain and range of the property. (Just using :has as a property name indicates a wide set of misconceptions, possibly from other types of languages.) So I'd suggest the name :hasDisease and the assertions:
:hasDisease rdfs:domain :People .
:hasDisease rdfs:range :Disease .
Third, you can assert that :John :hasDisease :Cancer and infer that John has a disease, given that :Cancer is a subclass of :Disease. This requires a standard RDFS reasoner. Also, given the domain and range definitions above, and an assertion :Joy :hasDisease :Gout, an RDFS reasoner will infer that :Joy a :Person and :Gout a :Disease.
There are a few OWL primers out there that you can find via Google. I'd suggest going over some of these to get a basic understanding of how OWL and reasoning profiles work.

How to get individual results while solving Einstein's riddle with OWL in Protégé?

I would like to better understand ontologies and reasoning. There is an interesting puzzle called Einstein's riddle on the net that can be solved with the help of ontologies and reasoning. I downloaded the OWL ontology from that site and imported it into Protege 4.0.2 (does not work with 4.1). I can start a reasoner by Reasoner → FaCT++, Reasoner → Classify…, but i don't know, how to visualize the individual results. How can I do this?
There are two ways in which you can visualise the results. Firstly, when you select the "Classes" Tab, you will see that there are two views available to you: the "Class hierarchy" view, which is the asserted taxonomy and the "Class Hierarchy View (inferred)", which is, as the name suggests, the inferred one. That gives you the class views. As Kaarel suggests, you can visualise the individuals reasoning in the Individuals tab.
Protege also allows you to add a number of other individuals views to the UI: make a new empty tab and then choose a view from the "Individuals View" sub-menue under the "Views" menue. Finally, you can use a number of external graphical tools to visualise: if you assert the inferred hierarchy and save it out to a file (in RDF-XML), you can then use tools such as Welkin, IsaViz etc. to get graphical representations.
After the reasoner has finished go to the Individuals-tab and look for axioms that have a yellow background. These axioms are the entailed ones. If the components of the puzzle (i.e. the men, pets, drinks, etc.) have been modeled as OWL individuals then you would see some new object property assertions that the reasoner has found between these individuals.
There are also other options for seeing the entailments:
View -> Ontology views -> Classification Results will show the list of entailed axioms. It might not show all the entailed axioms though, e.g. I've tried it with Protege 4.1 and didn't see any entailed object property assertions.
In the DL Query tab you can type in a class expression and have all its subclasses and individuals (including the entailed ones) listed. This might be the most natural way of exploring the entailments.
See also:
ACE View examples: contains the "Zebra Puzzle" example, works in Protege 4.1
Stackoverflow question: Solving “Who owns the Zebra” programmatically?: doesn't yet contain the OWL-based solution :(

Resources