stardog-union / pellet

Pellet is an OWL 2 reasoner in Java; open source (AGPL) and commercially licensed, commercial support available.
http://clarkparsia.com/pellet
Other
306 stars 151 forks source link

NPE when working on ontology with no classes contained in #28

Open LorenzBuehmann opened 9 years ago

LorenzBuehmann commented 9 years ago

The current implementation of Pellet does not work when we load an ontology with no classes and then e.g. ask for domains of a property.

The ontology:

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.w3.org/2002/07/owl#> .
[ rdf:type owl:Ontology
] .
<http://dl-learner.org/test/strings/stringValue> rdf:type owl:DatatypeProperty .
<http://dl-learner.org/test/strings/p0> rdf:type owl:NamedIndividual ;
                     <http://dl-learner.org/test/strings/stringValue> "X"^^xsd:string .

The example code:

File file = //load file here;
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory df = man.getOWLDataFactory();
OWLOntology ontology = man.loadOntologyFromOntologyDocument(file);
PrefixManager pm = new DefaultPrefixManager("http://dl-learner.org/test/strings/");
OWLDataProperty dp = df.getOWLDataProperty("stringValue", pm);
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner
reasoner.getDataPropertyDomains(dp, true); // NPE occurs

Exception:

java.lang.NullPointerException
    at org.mindswap.pellet.taxonomy.CDOptimizedTaxonomyBuilder.classify(CDOptimizedTaxonomyBuilder.java:826)
    at org.mindswap.pellet.taxonomy.CDOptimizedTaxonomyBuilder.classify(CDOptimizedTaxonomyBuilder.java:802)
    at org.mindswap.pellet.KnowledgeBase.getAllEquivalentClasses(KnowledgeBase.java:3565)
    at org.mindswap.pellet.KnowledgeBase.getEquivalentClasses(KnowledgeBase.java:3535)
    at com.clarkparsia.pellet.owlapiv3.PelletReasoner.getDataPropertyDomains(PelletReasoner.java:414)

The reason is in class CDOptimizedTaxonomyBuilder in line 826

ConceptFlag flag = conceptFlags.get( c );

The conceptFlags object is not created because the method classify() returns before because of an empty set of classes.