Cannot infer individuals types via Java API

27 views
Skip to first unread message

asca...@noemalife.com

unread,
Sep 12, 2014, 4:09:07 AM9/12/14
to elk-reasone...@googlegroups.com
Hi all,
it seems that I'm unable to inferrer individuals types via Java. The same ontology correctly infer types in protegè (proof is attached).

I'm using an equivalence class based on fixed datatype properties (e.g. name value "foo"^^string) and I know ELK 0.4.1, neither current master, support this, but luckily for me (and thank you to you!) the code under the elk-parent-datatypes branch does.


OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(inputStream);
OWLReasoner reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology);
reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);

List<InferredAxiomGenerator<? extends OWLAxiom>> axiomGenerators = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
axiomGenerators.add(new InferredClassAssertionAxiomGenerator());

InferredOntologyGenerator inferredOntologyGenerator = new InferredOntologyGenerator(reasoner, axiomGenerators);

OWLOntologyManager outputOntologyManager = OWLManager.createOWLOntologyManager();
OWLOntology outputOntology = outputOntologyManager.createOntology();
inferredOntologyGenerator.fillOntology(outputOntologyManager, outputOntology);

PrintWriter output = PrintWriter(System.out);
outputOntologyManager.saveOntology(outputOntology, new RDFXMLOntologyFormat(), output);

reasoner.dispose();

What I'm missing?

Please ask if you need more info.
Thank you!
members.png

Yevgeny Kazakov

unread,
Sep 12, 2014, 5:10:43 AM9/12/14
to elk-reasone...@googlegroups.com
Hi, just to confirm:

1. The problem appears only with ELK, i.e., other reasoners (e.g.,
HermiT) used with the same code generate all axioms correctly?
2. The problem is caused by datatypes, i.e., the code works correctly
for ontologies without datatypes?
3. You use the (unreleased) version of ELK from the branch
elk-parent-datatypes both in Protege and in your program?

In this case, it would be really helpful if you could provide a small
example ontology for which the problem takes place.

Best regards,

Yevgeny
> --
> You received this message because you are subscribed to the Google Groups
> "elk-reasoner-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elk-reasoner-disc...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

asca...@noemalife.com

unread,
Sep 12, 2014, 6:21:10 AM9/12/14
to elk-reasone...@googlegroups.com, yevgeny...@uni-ulm.de
Il giorno venerdì 12 settembre 2014 11:10:43 UTC+2, Yevgeny Kazakov ha scritto:
1. The problem appears only with ELK, i.e., other reasoners (e.g.,
HermiT) used with the same code generate all axioms correctly?

I tried both HermiT and Pellet, but they fail with different errors. By fail, I mean the Java program dies.
 
2. The problem is caused by datatypes, i.e., the code works correctly
for ontologies without datatypes?

I did a try removing the restrictions in my equivalence class and ELK correctly infer that element.
 
3. You use the (unreleased) version of ELK from the branch
elk-parent-datatypes both in Protege and in your program?

Yes, I did it that way. In fact I'm really surprised of the different behaviour.
 
In this case, it would be really helpful if you could provide a small
example ontology for which the problem takes place.

Attached.
Protegè (using ELK from that branch) inferred Test is of class EquivalentClazz, while Java code did not.

Thanks
ontology.rdf

asca...@noemalife.com

unread,
Sep 12, 2014, 6:24:54 AM9/12/14
to elk-reasone...@googlegroups.com, yevgeny...@uni-ulm.de
Il giorno venerdì 12 settembre 2014 12:21:10 UTC+2, asca...@noemalife.com ha scritto:
Attached.

I forgot to adjust RDF prefixes in the previous file before sending the mail, this one is correct. 
ontology.rdf

asca...@noemalife.com

unread,
Sep 12, 2014, 6:33:08 AM9/12/14
to elk-reasone...@googlegroups.com, yevgeny...@uni-ulm.de
Il giorno venerdì 12 settembre 2014 12:21:10 UTC+2, asca...@noemalife.com ha scritto:
Protegè (using ELK from that branch) inferred Test is of class EquivalentClazz, while Java code did not.

Oh wait! It seems that I was wrong, this simple ontology works correctly in both Protegè and Java code.
I'll do more investigations on my ontology and report any update.

Yevgeny Kazakov

unread,
Sep 16, 2014, 9:34:46 AM9/16/14
to asca...@noemalife.com, elk-reasone...@googlegroups.com
Any update on that? Did you manage to reproduce the problem?

asca...@noemalife.com

unread,
Sep 17, 2014, 9:07:53 AM9/17/14
to elk-reasone...@googlegroups.com, asca...@noemalife.com, yevgeny...@uni-ulm.de
Il giorno martedì 16 settembre 2014 15:34:46 UTC+2, Yevgeny Kazakov ha scritto:
Any update on that? Did you manage to reproduce the problem?

Hi, thank you for your interest. I just found out the issue and I'd like to hear from you if this behaviour is OK or not.

The thing is I initialize the reasoner with an initial ontology and then I add some axiom (the individuals that match my equivalence rule) to the reasoner root ontology later.
This way the reasoner does *not* infer my equivalence class. I run flush() after adding the axioms.

If I initialize the reasoner with an ontology which *contains* the individuals that match my equivalence rule then the reasoner correctly inferred the types.

Let me know if you need an example code/test for this.

Yevgeny Kazakov

unread,
Sep 17, 2014, 9:24:38 AM9/17/14
to ascarpino, elk-reasone...@googlegroups.com
Did you try to do it like in this example:

https://code.google.com/p/elk-reasoner/wiki/IncrementalReasoning

>
> Let me know if you need an example code/test for this.

Yes, please.

Are you missing inferences only for datatypes or all inferences?

Yevgeny

asca...@noemalife.com

unread,
Sep 17, 2014, 10:00:07 AM9/17/14
to elk-reasone...@googlegroups.com, asca...@noemalife.com, yevgeny...@uni-ulm.de
Il giorno mercoledì 17 settembre 2014 15:24:38 UTC+2, Yevgeny Kazakov ha scritto:
Did you try to do it like in this example:

https://code.google.com/p/elk-reasoner/wiki/IncrementalReasoning

Yes I did, but no luck.

Given the ontology in input (ontology.rdf) which contains the definitions of two properties, one class and the equivalence rule and given a second ontology (individuals.rdf) which contains the individuals, I do expect that ELK correctly infer that urn:foo/Test/1 is of type urn:foo:bar#RuleTest.

Using the following Java code (ELKInferTest.java) this isn't true (the output is in wrong.log), while, if I merge individuals.rdf into ontology.rdf I get the output shown in right.log.

Let me know if you need anything else. Thank you!
wrong.log
ELKInferTest.java
individuals.rdf
ontology.rdf
right.log

Yevgeny Kazakov

unread,
Sep 17, 2014, 10:13:55 AM9/17/14
to asca...@noemalife.com, elk-reasone...@googlegroups.com
Hi,

thanks for your example! We will investigate this problem and report back.

Best regards,

Yevgeny

Yevgeny Kazakov

unread,
Sep 18, 2014, 6:00:10 AM9/18/14
to ascarpino, elk-reasone...@googlegroups.com
Hi,

I looked at your example and I found several problems with you
"individuals.rdf.xml" file:

1. You use the uri "urn:foo/Test/1" in your assertion. This uri does
not occur in your "ontology.rdf.xml" file. Instead you use there
"&foo;Test".

2. There are no declarations for "foo:bar" and "foo:biz" properties in
"individuals.rdf.xml". OWL API parser does not know what kind of
properties are they (object properties, data properties, or annotation
properties) and parses your assertion axioms as annotation assertions
(http://www.w3.org/TR/owl2-syntax/#Annotation_Assertion) instead of
datatype assertions
(http://www.w3.org/TR/owl2-syntax/#Positive_Data_Property_Assertions).
You can see that if you load your ontology in Protege (inspect
"Ontology metrics"). Annotation assertion axioms (like in general all
annotations) are ignored by reasoners.

Attached is a corrected version of the file for which your program
gives the right output.

My advise: stay away from the OWL RDF/XML syntax or otherwise you have
lot's of problems caused by ambiguity / missing declarations. Use the
OWL XML or the OWL Functional Style syntax instead.

Yevgeny
individuals.rdf.xml

Yevgeny Kazakov

unread,
Sep 18, 2014, 6:19:09 AM9/18/14
to ascarpino, elk-reasone...@googlegroups.com
Actually, ignore the first point. I confused the uri referring to
individual and uri referring to the class. Uri "urn:foo/Test/1" refers
to the individual in your case. Attached the file with your original
uris (just added property declarations).

Yevgeny

On Thu, Sep 18, 2014 at 11:59 AM, Yevgeny Kazakov
individuals.rdf.xml

asca...@noemalife.com

unread,
Sep 18, 2014, 2:58:29 PM9/18/14
to elk-reasone...@googlegroups.com
Yeah it's exactly as you said!

I can't switch to OWL XML because Jena doesn't support it, but merging the class/properties I need into the individuals ontology fixed it.
Thank you very much! Really :-)

BTW, could I help in testing the elk-parent-datatypes branch so it get merged? Any specific test you need?

Yevgeny Kazakov

unread,
Sep 22, 2014, 12:33:27 PM9/22/14
to elk-reasone...@googlegroups.com
Thanks for your offer!
Feel free to fork our the elk-parent-datatypes branch on github:

https://github.com/klinovp/elk/tree/elk-parent-datatypes/elk-reasoner

You can submit high level reasoning tests in functional-style OWL
syntax. You do not need to know ELK internals for that. Just create an
OWL ontology and another OWL ontology with expected subsumption /
instance results. The classification and realization tests are located
in separate folders, which can be further divided on subfolders
according to the types of the tests:

https://github.com/klinovp/elk/tree/elk-parent-datatypes/elk-reasoner/src/test/resources/classification_test_input
https://github.com/klinovp/elk/tree/elk-parent-datatypes/elk-reasoner/src/test/resources/realization_test_input

The tests should run automatically during the build (or they can be
run manually, e.g., in eclipse).
You can add your tests testing particular features you are interested
in and submit pull requests. It would be also useful for us to know
which datatypes and facets are most useful. We would be also
interested to know if there are performance problems.

We are currently working on a release 0.5 which provides code for
generating proofs / explanations, so the datatypes will probably not
be included in this release, but we are going to merge them for the
next release.

Best regards,

Yevgeny

Yevgeny Kazakov

unread,
Sep 23, 2014, 4:36:37 AM9/23/14
to elk-reasone...@googlegroups.com
B.t.w., here is some more information on specification of ELK reasoner
test files:

https://code.google.com/p/elk-reasoner/wiki/Testing

Yevgeny
Reply all
Reply to author
Forward
0 new messages