如何使用Java或pellet将SWRL规则添加到Ontology中?

时间:2016-05-27 15:32:37

标签: java owl pellet swrl

我没有使用Protégé为我的本体添加规则,而是希望使用Java或pellet将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);

1 个答案:

答案 0 :(得分:2)

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

文档可用here