【问题标题】:How to add SWRL rules to an Ontology using Java or pellet?如何使用 Java 或颗粒将 SWRL 规则添加到本体?
【发布时间】:2016-05-27 15:32:37
【问题描述】:

我不想使用 Protégé 向我的本体添加规则,而是想使用 Java 或 Pullet 向本体添加 SWRL 规则。

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

[课程(?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 pellet swrl


    【解决方案1】:

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

    文档可用here

    【讨论】:

    • 嗨,我正在尝试添加 swrl 规则并使用 java 和 owl api 运行推理器,但是,我迷路了,你能帮我举个例子吗?请 Enayat,Ignazio
    猜你喜欢
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多