Jena Reasoner无法推断

问题描述

我是本体的新手。最近,我正在尝试使用 Jena API 进行推断。我参考了this article的回答。但是,问题是我的 Jena 无法推断。 我的代码写在下面。我的本体文件here ,它包含 swrl 规则和一些实例。 我试图在保护中进行推断,并且它有效。所以,这意味着我的规则没问题。谁能告诉我我的代码有什么问题,或者如何纠正它?谢谢!

    String baseURI = "http://www.semanticweb.org/ncuis/ontologies/2021/2/People#";
    String ns = "http://www.semanticweb.org/ncuis/ontologies/2021/2/People#";
    OntModel ontModel = ModelFactory.createOntologyModel();
    String inputFileName = "src/main/java/org/isq/Onto/People.owl";

    // create ontology model using jena
    InputStream in = FileManager.get().open(inputFileName);
    try {
        File file = new File(inputFileName);
        FileReader reader = new FileReader(file);
        ontModel.read(reader,null);
    } catch (Exception e) {
        e.printstacktrace();
    }

    // Inferring using Jena: https://stackoverflow.com/questions/3024273/inferring-using-jena
    reasoner reasoner = reasonerRegistry.getoWLreasoner();
    reasoner = reasoner.bindSchema(ontModel);
    // Obtain standard OWL-DL spec and attach the pellet reasoner
    OntModelSpec ontModelSpec = OntModelSpec.OWL_DL_MEM;
    ontModelSpec.setreasoner(reasoner);
    // Create ontology model with reasoner support
    OntModel model = ModelFactory.createOntologyModel(ontModelSpec,ontModel);

    OntClass marPerson = model.getontClass(ns + "MarriedPerson"); // this is the uri for MarriedPerson class
    ExtendedIterator married = marPerson.listInstances();
    while(married.hasNext()) {
        OntResource mp = (OntResource) married.next();
        System.out.println(mp.getLocalName());
    } // it should infer two names

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...