如何使用Java或Pellet向本体添加SWRL规则?

3

我想使用Java或Pellet向本体中添加SWRL规则,而不是使用Protégé。例如,这是我想要导入到我的本体中的规则:

[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);
1个回答

3

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

文档可在此处获取


嗨,我正在尝试使用Java和OWL API添加SWRL规则并运行推理器,但是我迷失了,你能帮我提供一个示例吗?谢谢 Enayat,Ignazio - Moneer Kamal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接