繁体   English   中英

如何使用 Java 或颗粒将 SWRL 规则添加到本体?

[英]How to add SWRL rules to an Ontology using Java or pellet?

我不想使用 Protégé 向我的本体添加规则,而是想使用 Java 或颗粒将 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 使用的过程相同。

文档可在此处获得

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM