首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Java或pellet将SWRL规则添加到本体中?

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

Stack Overflow用户
提问于 2016-05-27 15:32:37
回答 1查看 1.3K关注 0票数 3

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

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

课程(X),teacherOf(?y,?x),worksFor(?y,?z) => coursePresentedInUniversity(?x,?z)

我想将以下代码添加到本体中:

代码语言:javascript
复制
<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>

有人能指给我一个示例代码吗?

实际上,我写了下面的代码,但它没有工作!

代码语言:javascript
复制
    Rule mynewRule=new Rule(ruleHead,ruleBody);
    PelletReasoner pelletReasoner =com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner(testOntology );
    KnowledgeBase knowledgeBase=pelletReasoner.getKB();
    knowledgeBase.addRule(mynewRule);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-28 09:28:44

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

文档可获得这里

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37487339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档