[英]How can I transform the rules to SWRL code?
Let's assume we have the following rule: 我们假设我们有以下规则:
Course(?x), teacherOf(?y,?x), worksFor(?y,?z) => coursePresentedInUniversity(?x,?z)
课程(?x),teacherOf(?y,?x),worksFor(?y,?z)=> coursePresentedInUniversity(?x,?z)
Is there any library in pellet or java to convert the above rule to SWRL code? pellet或java中是否有任何库将上述规则转换为SWRL代码? for example, to the following:
例如,以下内容:
<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>
I know that pellet can do the reverse (using reasoner.getKB().getRules()
), but I don't know if there is anything to transform the representation to the SWRL XML code. 我知道pellet可以反过来(使用
reasoner.getKB().getRules()
),但我不知道是否有任何东西可以将表示转换为SWRL XML代码。 Thanks! 谢谢!
For converting a string as SWRL rule in an ontology, according to this document some steps should be done: 1) the string should be parsed and tokenized. 为了在本体中将字符串转换为SWRL规则,根据本文档,应该执行以下步骤:1)应该对字符串进行解析和标记化。 2) SWRL rule should be created using SWRLRule and SWRLObjectProperties.
2)应使用SWRLRule和SWRLObjectProperties创建SWRL规则。 3) apply and save the changes in the ontology, For example, for
teacherOf(?y,?x)
we can write the following code: 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);
You can enter SWRL rules in presentation syntax in the Protégé editor then save your ontology in RDF/XML format. 您可以在Protégé编辑器中以演示语法输入SWRL规则,然后以RDF / XML格式保存本体。 If you'd like to do the same in your code then you'll need to use the ManchesterOWLSyntaxParserImpl class from OWLAPI to parse the rule.
如果您想在代码中执行相同的操作,则需要使用OWLAPI中的ManchesterOWLSyntaxParserImpl类来解析规则。 You can then use OWLAPI to save the rule(s) in RDF/XML format.
然后,您可以使用OWLAPI以RDF / XML格式保存规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.