java - 如何使用 Java 或 pellet 将 SWRL 规则添加到本体中?

标签 java owl pellet swrl

我不想使用 Protégé 将规则添加到我的本体中,而是想使用 Java 或 pellet 将 SWRL 规则添加到本体中。

例如,这是我要导入到我的本体中的规则:

[Course(?x),teacherOf(?y,?x),worksFor(?y,?z)] => [coursePresentedInUniversity(?x,?z)]

我想在本体中添加如下代码:

<swrl:Imp rdf:about="#CoursePresentedInUniversityRule">
    <swrl:head rdf:parseType="Collection">  
        <swrl:IndividualPropertyAtom>
                <swrl:propertyPredicate rdf:resource="#coursePresentedInUniversity" />
                <swrl:argument1 rdf:resource="#x" />
                <swrl:argument2 rdf:resource="#z" />
        </swrl:IndividualPropertyAtom>
    </swrl:head>
    <swrl:body rdf:parseType="Collection">
        <swrl:ClassAtom>
            <swrl:classPredicate rdf:resource="#Course" />
            <swrl:argument1 rdf:resource="#x" />
        </swrl:ClassAtom>

        <swrl:IndividualPropertyAtom>
            <swrl:propertyPredicate rdf:resource="#teacherOf" />
            <swrl:argument1 rdf:resource="#y" />
            <swrl:argument2 rdf:resource="#x" />
        </swrl:IndividualPropertyAtom>
        <swrl:IndividualPropertyAtom>
            <swrl:propertyPredicate rdf:resource="#worksFor" />
            <swrl:argument1 rdf:resource="#y" />
            <swrl:argument2 rdf:resource="#z" />
        </swrl:IndividualPropertyAtom>

    </swrl:body>
</swrl:Imp>

谁能给我指出一个示例代码来做到这一点?

其实我写了下面的代码,但是没有成功!

    Rule mynewRule=new Rule(ruleHead,ruleBody);
    PelletReasoner pelletReasoner =com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner(testOntology );
    KnowledgeBase knowledgeBase=pelletReasoner.getKB();
    knowledgeBase.addRule(mynewRule);

最佳答案

使用 Java 代码的一种方法是通过 OWL API - OWLDataFactory 类具有创建 SWRL 规则的方法,生成的规则可以添加到本体并保存 - 它与使用的过程相同由 Protege 4 和 5 提供。

文档可用here

关于java - 如何使用 Java 或 pellet 将 SWRL 规则添加到本体中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37487339/

相关文章:

rdf - 使用Pellet作为推理机的OutOfMemoryError

java - 使用 Pellet Reasoner 监控推理进度

java - 在 Eclipse 中将多个 .java 文件合并为一个 .jar 文件(它们相互依赖)

Java - JDBC 驱动程序和 MySQL 数据库连接问题

java - 不能用耶拿写大猫头鹰文件

java - Protégé OWL API 编程

java - 用枚举进行反射(reflection)

Java-读取自定义文件扩展名问题

java - OWL中的CRUD操作

rdf - sparql 查询中三元组的顺序会影响结果吗?