让我们假设我们有以下规则:
课程(X),teacherOf(?y,?x),worksFor(?y,?z) => coursePresentedInUniversity(?x,?z)
在pellet或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>
我知道pellet可以做相反的事情(使用reasoner.getKB().getRules()
),但我不知道是否有任何东西可以将表示转换为SWRL代码。谢谢!
发布于 2016-05-30 16:25:23
为了在本体中将字符串转换为SWRL规则,根据本文件,应该执行一些步骤: 1)字符串应该被解析和标记。2)使用SWRLRule和SWRLObjectProperties创建SWRL规则。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-26 02:49:26
您可以在普罗泰编辑器中输入表示语法中的SWRL规则,然后以RDF/XML格式保存本体。如果您想在代码中执行同样的操作,那么需要使用来自OWLAPI的ManchesterOWLSyntaxParserImpl类来解析规则。然后可以使用OWLAPI以RDF/XML格式保存规则。
https://stackoverflow.com/questions/37449215
复制相似问题