0

我正在尝试用 owl api 做一些简单的事情。为此,我创建了一个本体,组成了一些类和 SubClassOf Axioms。在此之后,我尝试使用 Reasoner Hermit 来处理它。但是当我调用一个隐士方法时,我得到一个空指针异常。这是我的实际示例:

public class Main {
    static OWLOntologyManager manager = null;
    static IRI ontologyIRI = null;
    static IRI documentIRI = null;
    static OWLOntology ontology = null;
    static OWLDataFactory factory = null;       
    static OWLReasoner hermit = null;       
    static HashMap<String, HashSet<String>> keywords = new HashMap<String, HashSet<String>>();

public static void main(String[] args) throws IOException, OWLException{

    manager = OWLManager.createOWLOntologyManager();
    ontologyIRI = IRI.create("http://www.someurl.com/myOnto.owl");  
    documentIRI = IRI.create("file:/src/main/resources.xml");   
    SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI); 
    manager.addIRIMapper(mapper);   
    ontology = manager.createOntology(ontologyIRI); 
    factory = manager.getOWLDataFactory();     

    OWLClass main = factory.getOWLClass(
            IRI.create(ontologyIRI + "#main"));

    OWLClass clsA = factory.getOWLClass(
                IRI.create(ontologyIRI + "#test"));

    OWLAxiom axiom = factory.getOWLSubClassOfAxiom(clsA, main);
        AddAxiom addAxiom = new AddAxiom(ontology, axiom);

    manager.applyChange(addAxiom);

    //I insert some more classes and axioms here

    ReasonerFactory fac = new ReasonerFactory();
    hermit = fac.createReasoner(ontology);

    // Print the hierarchy, this works fine
    HirarchyPrinter hp = new HirarchyPrinter(manager, hermit);

    hp.printHierarchy(ontology, clazz);

    //now here I want to access the data, e.g. starting with this call:

    hermit.getSubClasses(main, false);
}

但我总是得到一个异常,总是以 getTableau 调用结束

Exception in thread "main" java.lang.NullPointerException
at org.semanticweb.HermiT.Reasoner.getTableau(Unknown Source)
at org.semanticweb.HermiT.Reasoner.isConsistent(Unknown Source)
at org.semanticweb.HermiT.Reasoner.throwInconsistentOntologyExceptionIfNecessary(Unknown Source)
at org.semanticweb.HermiT.Reasoner.checkPreConditions(Unknown Source)
at org.semanticweb.HermiT.Reasoner.getHierarchyNode(Unknown Source)
at org.semanticweb.HermiT.Reasoner.getSubClasses(Unknown Source)
at main.java.Main.main(Main.java:93)

我不知道是什么导致了这个异常,也无法在任何地方找到任何类似的案例。

问候,丹尼尔

4

0 回答 0