Search Mailing List Archives
[protege-discussion] Exception in inference api
Timothy Redmond
tredmond at stanford.edu
Sun Oct 10 11:44:48 PDT 2010
The types of questions you have been asking are better asked on the p4
mailing list as it is about the Protege 4 owl editor. Instructions for
joining that list are here:
http://mailman.stanford.edu/mailman/listinfo/p4-feedback
I used your code pretty much verbatim and did not see the null pointer
exception. In fact the code pretty much did what I expected. I think
that this issue can be cleared up if you supply a bit more information.
> but I have an exception in this line:
> ontologygenerator.fillOntology(ontologymanager,ontology);
> this exception says: java.lang.NullPointerException
> I don't know what i should do and what is wrong.
I suspect that we would know what is wrong immediately if we saw the
exception stack trace. A null pointer that actually thown on that line
would seem to be impossible with the code you sent (based on Java
principles only). The only way to get the null pointer on that line is
if the ontologygenerator variable is null but it is assigned to a
constructed value in the previous line.
So I think that your exception is generated somewhere in code called by
the line
ontologygenerator.fillOntology(ontologymanager,ontology).
Somewhere down inside there something has not been initialized
correctly. An obvious guess is that things went wrong because the
OWLOntology ontology=ontologymanager.loadOntology(IRI.create(OwlUri));
line did not successfully load an ontology. But I (accidentally
actually) tested that and it results in an exception at that line. So I
would guess that this is not the issue either.
I have some other immediate comments on your code.
> I used protege 4.1 beta build 209 api, and I have a problem in
> inference api.
All the code you have supplied is actually based on the Manchester OWL
API (owlapi.sourceforge.net) which is an important library used by
Protege 4.1. I didn't see any Protege specific code in your sample.
In this code there is the line:
OWLReasonerFactory reasonerfactory= new Reasoner.ReasonerFactory();
If you are planning on using this code in Protege 4.1 then this is not
the recommended approach. But your approach may be best for making
quick little applications that you can test before integrating with
Protege 4.1. A better approach if you integrate your code into Protege
4.1 would be something like
OWLReasoner owlreasoner = getOWLModelManager().getReasoner();
if (owlreasoner instanceof NoOpReasoner) {
... tell the user to initialize his reasoner ...
return;
}
else if (!owlreasoner.getPendingChanges().isEmpty()) {
owlreasoner.flush();
}
Most plugin types (view components, menus) will have a
getOWLModelManager() method. I add the reasoner.flush() call here
because I figure that an export inferred axioms operation is
sufficiently expensive that it makes sense to bring the reasoner up to
date first.
Then later you do this step:
owlreasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
It is a good idea to do the precompute step here but you chose the wrong
one for the task that follows. When you create the
InferredOntologyGenerator, you tell it to compute inferred class
assertion axioms (e.g. statements that an individual is in a class).
Precomputing the class hierarchy will not help with this task.
-Timothy
On 10/10/2010 07:06 AM, Soha Said wrote:
> I used protege 4.1 beta build 209 api, and I have a problem in
> inference api.
> This is the snapshot of code that I used to get inferencing:
> OWLOntologyManager ontologymanager=OWLManager.createOWLOntologyManager();
> OWLOntology
> ontology=ontologymanager.loadOntology(IRI.create(OwlUri));
> OWLDataFactory factory=ontologymanager.getOWLDataFactory();
> OWLReasonerFactory reasonerfactory= new
> Reasoner.ReasonerFactory();
> OWLReasoner
> owlreasoner=reasonerfactory.createNonBufferingReasoner(ontology);
>
> owlreasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
>
> List<InferredAxiomGenerator<? extends OWLAxiom>> InferredGenerator =
> new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
> InferredGenerator.add(new
> InferredClassAssertionAxiomGenerator());
> InferredOntologyGenerator ontologygenerator=new
> InferredOntologyGenerator(owlreasoner,InferredGenerator);
> ontologygenerator.fillOntology(ontologymanager,ontology);
> ontologymanager.saveOntology(ontology,IRI.create(OwlUri));
> but I have an exception in this line:
> ontologygenerator.fillOntology(ontologymanager,ontology);
> this exception says: java.lang.NullPointerException
> I don't know what i should do and what is wrong.
> Thanks in advance
> Soha Said
>
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101010/55e712f0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SohaSaid.java
Type: text/x-java
Size: 1835 bytes
Desc: not available
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101010/55e712f0/attachment.java>
More information about the protege-discussion
mailing list