How to use OWLReasoner to update an ontology - owl-api

I'm new to the OWL API and I was wondering if there was a way to update an ontology with all the new relations picked up by the reasoner (HermiT). I couldn't find a tutorial or much documentation, so I assumed calling
reasoner.classifyClasses();
reasoner.classifyDataProperties();
reasoner.classifyObjectProperties();
reasoner.precomputeInferences();
reasoner.flush();
would classify the new relations. Then, I'm not sure how to translate these new relations to create an updated ontology. I have an idea of how I could manually iterate through new relations and add them if they aren't present in the ontology, but I'm looking for an easier way to do this. Also, I'm not entirely sure if the above code reasons all the new relations for me, so let me know if I should make any corrections.

You can use InferredOntologyGenerator for that purpose. The class can be created with a reasoner as input and the InferredOntologyGenerator::fillOntology method to add all the axioms that can be inferred to a new ontology.
Note that axiom generation can be a very slow operation. Try with a small ontology at first, to see whether the result is what you need.

Related

Is it possible to filter the class display in Protegé?

I am designing a new ontology, which references the (very large!) Ontology of Units of Measure (om-2): http://www.ontology-of-units-of-measure.org/page/om-2
This makes it hard to work with Protegé because it seems that I am left with one of two bad alternatives:
The small number of classes in my ontology are swamped in the display by om-2 classes (displaying with prefix helps, but only a little).
I don't include om-2 in the Protegé project and just refer to classes from there. As far as I can tell, this hampers Protegé's ability to work with a DL reasoner.
Is there some way to tell Protegé to filter the display and hide the om-2 classes? Being able to toggle this would be a huge help.

testing framework for OWL ontologies

Is there a testing framework or tool or Protege's plugin for functional testing of OWL ontologies? e.g. to check presence or absence of some axioms in an onology,
to apply some test facts to the ontology and analyse new axioms obtained as a result.
If I understand you correctly you, given an ontology you want to figure out
whether the stated axioms are correct and
whether there are any missing axioms.
(1) OntoComP is a plugin for Protege 4.x. Given an ontology it will, by asking the user questions, either add counter examples or add additional axioms to the ontology. You can read more on this here.
(2) Scenario testing for OWL ontologies defines a method via which you can setup "scenarios" to test that your ontology adheres to functional requirements. This is an approach I have defined in my MSc dissertation and which we have used successfully to validate complex functional requirements for a hotel management group.
(3) You can use the OWL API to test whether the required axioms hold:
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(ontologyFileIRI);
OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
OWLClass classA = dataFactory.getOWLClass(ontologyIRI + "#A");
OWLClass classD = dataFactory.getOWLClass(ontologyIRI + "#D");
OWLAxiom dSubclassOfA = dataFactory.getOWLSubClassOfAxiom(classD, classA);
reasoner.isConsistent();
System.out.println("D subclass of A = " + reasoner.isEntailed(dSubclassOfA));
The complete example code for this you can find here.
So, this is a challenge to apply testing procedures (functional tests) to a core (i.e. OWL2 driven knowledge base) of an ontology based application.
You can start with mentioned above:
-RDFUnit (https://github.com/AKSW/RDFUnit), but it seems to be very SPARQL specific.
Also things exist like:
-evOWLuator (https://github.com/sisinflab-swot/evowluator).
It is Python based, current version is 0.1.1, and they declare the support for ontology classification, consistency and 'matchmaking' reasoning tasks.
-Scone (https://bitbucket.org/malefort/scone/src/default/). It is quite perspective because allows usage of a controlled natural language, however is still in an early development stage.
And some research efforts are too.
-Again you are free to dive in DIY with OWL API.

Can I use OWL API to enforce specific subject-predicate-object relationships?

I am working on a project using RDF data and I am thinking about implementing a data cleanup method which will run against an RDF triples dataset and flag triples which do not match a certain pattern, based on a custom ontology.
For example, I would like to enforce that class http://myontology/A must denote http://myontology/Busing the predicate http://myontology/denotes. Any instance of Class A which does not denote an instance of Class B should be flagged.
I am wondering if a tool such as the OWLReasoner from OWL-API would have the capability to accomplish something like this, if I designed a custom axiom for the Reasoner. I have reviewed the documentation here: http://owlcs.github.io/owlapi/apidocs_4/org/semanticweb/owlapi/reasoner/OWLReasoner.html
It seems to me that the methods available with the Reasoner might not be up for the purpose which I would like to use them for, but I'm wondering if anyone has experience using OWL-API for this purpose, or knows another tool which could do the trick.
Generally speaking, OWL reasoning is not well suited to finding information that's missing in the input and flagging it up: for example, if you create a class that asserts that an instance of A has exactly one denote relation to an instance of B, and have an instance of A that does not, under Open World assumption the reasoner will just assume that the missing statement is not available, not that you're in violation.
It would be possible to detect incorrect denote uses - if, instead of relating to an instance of B, the relation was to an instance of a class disjoint with B. But this seems a different use case than the one you're after.
You can implement code with the OWL API to do this check, but it likely wouldn't benefit from the ability to reason, and given that you're working at the RDF level I'd think an API like Apache Jena might actually work better for you (you won't need to worry if your input file is not OWL compliant, for example).

Generate individuals from OWL class defintion

I'm fairly new to ontologies and have the following situation:
Given a class definition, I want to automatically generate individuals based on all possible combinations of a given restriction.
For example:
Let's say a "Pizza" class has the property "hasTopping" which is supposed to be linked to an individual of class "Topping". I want to generate an individual of the class Pizza for each individual existing for a Topping. If there are two Topping individuals, Tomato and Cheese, I want to create one Pizza individual with "hasTopping Tomato" and one with "hasTopping Cheese".
Is there any general way to generate individuals in ontologies like this? (As an alternative to implement it myself.)
Is this "violating" the intent/purpose of ontologies in general? Would this usually be handled in a different way? (I'm not completely familiar with ontologies yet.)
There's no standard method to do this, so I think you'll have to implement it yourself. The Leigh University Benchmark does something similar, so it might provide you with some ideas: http://swat.cse.lehigh.edu/projects/lubm/
I don't think this violates the idea behind ontologies at all - seems quite straightforward. There is no best practice for it, so however you choose to implement it will probably be adequate.

MVC: Correct pattern to reference objects from a different model

I'm using CakePHP2.3 and my app has many associations between models. It's very common that a controller action will involve manipulating data from another model. So I start to write a method in the model class to keep the controllers skinny... But in these situations, I'm never sure which model the method should go in?
Here's an example. Say I have two models: Book and Author. Author hasMany Book. In the /books/add view I might want to show a drop-down list of popular authors for the user to select as associated with that book. So I need to write a method in one of the two models. Should I...
A. Write a method in the Author model class and call that method from inside the BooksController::add() action...
$this->Author->get_popular_authors()
B. Write a method in the Book model class that instantiates the other model and uses it's find functions... Ex:
//Inside Book::get_popular_authors()
$Author = new Author();
$populars = $Author->find('all', $options);
return $populars;
I think my question is the same as asking "what is the best practice for writing model methods that primarily deal with associations between another model?" How best to decide which model that method should belong to? Thanks in advance.
PS: I'm not interested in hearing whether you thinking CakePHP sucks or isn't "true" MVC. This question is about MVC design pattern, not framework(s).
IMHO the function should be in the model that most closely matches the data you're trying to retrieve. Models are the "data layer".
So if you're fetching "popular authors", the function should be in the Author model, and so on.
Sometimes a function won't fit any model "cleanly", so you just pick one and continue. There are much more productive design decisions to concern yourself with. :)
BTW, in Cake, related models can be accessed without fetching "other" the model object. So if Book is related to Author:
//BooksController
$this->Book->Author->get_popular_authors();
//Book Model
$this->Author->get_popular_authors();
ref: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#relationship-types
Follow the coding standards: get_popular_authors() this should be camel cased getPopularAuthors().
My guess is further that you want to display a list of popular authors. I would implement this using an element and cache that element and fetching the data in that element using requestAction() to fetch the data from the Authors controller (the action calls the model method).
This way the code is in the "right" place, your element is cached (performance bonus) and reuseable within any place.
That brings me back to
"what is the best practice for writing model methods that primarily
deal with associations between another model?"
In theory you can stuff your code into any model and call it through the assocs. I would say common sense applies here: Your method should be implement in the model/controller it matches the most. Is it user related? User model/controller. Is it a book that belongs to an user? Book model/controller.
I would always try to keep the coupling low and put the code into a specific domain. See also separation of concerns.
I think the key point to answer your question is defined by your specifications: "... popular authors for the user to select as associated with that book.".
That, in addition to the fact that you fetch all the authors, makes me ask:
What is the criteria that you will use to determine which authors are popular?
I doubt it, but if that depends on the current book being added, or some previous fields the user entered, there's some sense in adopting solution B and write the logic inside the Book model.
More likely solution A is the correct one because your case needs the code to find popular authors only in the add action of the Book controller. It is a "feature" of the add action only and so it should be coded inside the Author model to retrieve the list and called by the add action when preparing the "empty" form to pass the list to the view.
Furthermore, it would make sense to write some similar code inside the Book model if you wanted, e.g., to display all the other books from the same author.
In this case you seem to want popular authors (those with more books ?), so this clearly is an "extra feature" of the Author model (That you could even code as a custom find method).
In any case, as stated by others as well, there's no need to re-load the Author model as it is automatically loaded via its association with Books.
Look out for Premature Optimization. Just build your project till it works. You can always optimize your code or mvc patterns after you do a review of your code. And most important after your project is done most of the time you will see a more clear or better way to do it faster/smarter and better than you did before.
You can't and never will build a perfect mvc or project in one time. You need to find yourself a way of working you like or prefer and in time you'll learn how to improve your coding.
See for more information about Premature Optimization

Resources