2

假设我们有以下规则:

Course(?x), teacherOf(?y,?x),worksFor(?y,?z) => coursePresentedInUniversity(?x,?z)

颗粒或 java 中是否有任何库可以将上述规则转换为 SWRL 代码?例如,以下内容:

<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>

我知道颗粒可以做相反的事情(使用reasoner.getKB().getRules()),但我不知道是否有任何东西可以将表示转换为 SWRL XML 代码。谢谢!

4

2 回答 2

2

您可以在Protégé编辑器中以表示语法输入 SWRL 规则,然后以 RDF/XML 格式保存您的本体。如果您想在代码中执行相同的操作,则需要使用 OWLAPI 中的ManchesterOWLSyntaxParserImpl类来解析规则。然后,您可以使用 OWLAPI 以 RDF/XML 格式保存规则。

于 2016-05-26T02:49:26.353 回答
2

为了将字符串转换为本体中的 SWRL 规则,根据本文档,应该执行一些步骤:1) 应该对字符串进行解析和标记化。2) SWRL 规则应使用 SWRLRule 和 SWRLObjectProperties 创建。3)应用并保存本体中的更改,例如,teacherOf(?y,?x)我们可以编写如下代码:

    OWLObjectProperty teacherP= factory.getOWLObjectProperty(IRI
            .create(ontologyIRI + "#teacherOf"));

    SWRLVariable var1 = factory.getSWRLVariable(IRI.create(ontologyIRI
            + "#y"));
    SWRLVariable var2 = factory.getSWRLVariable(IRI.create(ontologyIRI
            + "#x"));
    SWRLObjectPropertyAtom teacherAtom = factory.getSWRLObjectPropertyAtom(
            teacherP, var1, var2);
    Set<SWRLAtom> SWRLatomList= new HashSet<SWRLAtom>();
    SWRLatomList.add(teacherAtom);

...

    SWRLRule teacherRule = factory.getSWRLRule(SWRLatomList,
            Collections.singleton(headAtom));
    ontologyManager.applyChange(new AddAxiom(testOntology, teacherRule ));
    ontologyManager.saveOntology(testOntology);
于 2016-05-30T16:25:23.700 回答