On Mon, Mar 18, 2013 at 10:24 AM, Ed Swing <[email protected]> wrote:
> I have noticed a problem within Jena when dealing with classes with multiple
> property restrictions. Here's the snippet of Java code:
>
> OntModel m =
> ModelFactory
> .createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
> FileInputStream inStream = new FileInputStream(args[0]);
> m.read(inStream, null);
> inStream.close();
> System.err.println("Done Read");
> int cnt = 0;
> for (Iterator<OntClass> clsIter = m.listClasses(); clsIter
> .hasNext(); cnt++) {
> OntClass cls = clsIter.next();
> System.out.println("CLS: " + cls.getLocalName());
> }
>
> And here's the offending class in the ontology (all mentioned properties and
> other classes are well-defined):
>
> <owl:Class rdf:ID="TravelEvent">
> <rdfs:subClassOf rdf:resource="#Event" />
> <rdfs:subClassOf>
> <owl:Restriction>
> <owl:onProperty rdf:resource="#actor" />
> <owl:allValuesFrom rdf:resource="#Person" />
> </owl:Restriction>
> </rdfs:subClassOf>
> <rdfs:subClassOf>
> <owl:Restriction>
> <owl:onProperty rdf:resource="#destination" />
> <owl:cardinality
> rdf:datatype="&xsd;nonNegativeInteger">1
> </owl:cardinality>
> </owl:Restriction>
> </rdfs:subClassOf>
> </owl:Class>
>
> When I run the code, it runs out of Java heap space. However, when I remove
> the destination cardinality restriction, it works fine. I have other classes
> that have multiple cardinality restrictions.
>
> Here's the definition of destination and its parent property:
> <owl:ObjectProperty rdf:ID="hasLocation">
> <rdfs:domain rdf:resource="#Event" />
> <rdfs:range rdf:resource="#Location" />
> </owl:ObjectProperty>
> <owl:ObjectProperty rdf:ID="destination">
> <rdf:type rdf:resource="&owl;FunctionalProperty" />
> <rdfs:subPropertyOf rdf:resource="#hasLocation"/>
> <rdfs:domain rdf:resource="#TravelEvent" />
> </owl:ObjectProperty>
>
> I added the FunctionalProperty definition to replace the cardinality
> restriction; it wasn't in the original.
>
> Because I can use a FunctionalProperty here, I can work around the issue.
> However, I'm not sure why the simple addition of a single restriction would
> blow out the memory. The entire ontology has less than 100 defined classes.
> This probably should be checked and fixed in the Jena code.
One quick note about the workaround: cardinality 1 means that there
is exactly one value for the property; declaring the property to be a
functional property means that there is *at most* 1 value, but there
could still be none. (That terminology threw me off for a long time.
I come from a logical/mathematical background and would have called it
a PartialFunctionalProperty or something.) I don't know whether that
makes a difference in the results you'll get, but be aware of the
difference.
I didn't attempt to reproduce the symptoms you're seeing here, but I
would note that the Jena reasoners are rule-based, and not complete
for OWL (not in the sense that they're not done, but rather that they
can't generate all the inferences that actually follow according to
OWL). In particular, some restrictions, such as cardinality, can be
particular challenges. In the rule reasoner factory [1] that creates
a reasoner for that OntModelSpec, there is (in declaring the
capabilities of the reasoner):
.addProperty(ReasonerVocabulary.supportsP, OWL.unionOf
) // Only partial
.addProperty(ReasonerVocabulary.supportsP,
OWL.minCardinality ) // Only partial
.addProperty(ReasonerVocabulary.supportsP,
OWL.maxCardinality ) // Only partial
.addProperty(ReasonerVocabulary.supportsP,
OWL.cardinality ) // Only partial
.addProperty(ReasonerVocabulary.supportsP,
OWL.someValuesFrom) // Only partial
.addProperty(ReasonerVocabulary.supportsP,
OWL.allValuesFrom ) // Only partial
I'd suggest you try using the Pellet reasoner and see what sort of
results you get. My personal experience has been that using the Jena
reasoners is great, if they're sufficient for your purposes (they're
very nice if you're working with plain RDF and want to add some
rules), but move to a complete reasoner if you're using more
expressive constructs and running into problems.
//JT
[1]
https://svn.apache.org/repos/asf/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasonerFactory.java
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/