我似乎无法弄清楚如何 OR ( ObjectUnionOf
?) 一组 AND ( ObjectIntersectionOf
) 规则。当在 protégé 中打开 OWL 文件时,我的代码产生的是规则 (has_difi_min some double[<= "184.84"^^double]) 和 (has_mean_ndvi some double[<= "0.3428"^^double]),等等。分离“规则集”,如下图所示。
我的 OWLAPI 代码:
/* write rules */
// OWLObjectIntersectionOf intersection = null;
OWLClassExpression firstRuleSet = null;
OWLClass owlCls = null;
OWLObjectUnionOf union = null;
Iterator it = rules.map.entrySet().iterator();
Set<OWLClassExpression> unionSet = new HashSet<OWLClassExpression>();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
String currCls = (String) pair.getKey();
owlCls = factory.getOWLClass(IRI.create("#" + currCls));
ArrayList<owlRuleSet> currRuleset = (ArrayList<owlRuleSet>) pair.getValue();
for (int i = 0; i < currRuleset.size(); i++) {
firstRuleSet = factory.getOWLObjectIntersectionOf(currRuleset.get(i).getRuleList(currCls))
union = factory.getOWLObjectUnionOf(firstRuleSet);
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(owlCls, union));
}
}
manager.saveOntology(ontology);
这就是它的样子:我希望这些线是 OR。
编辑:谢谢伊格纳齐奥!我的 OWLAPI 代码现在看起来像这样:
/* write rules */
OWLClass owlCls = null;
OWLObjectUnionOf totalUnion = null;
Iterator it = rules.map.entrySet().iterator();
Set<OWLClassExpression> unionSet = new HashSet<OWLClassExpression>();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
String currCls = (String) pair.getKey();
owlCls = factory.getOWLClass(IRI.create("#" + currCls));
ArrayList<owlRuleSet> currRuleset = (ArrayList<owlRuleSet>) pair.getValue();
for (int i = 0; i < currRuleset.size(); i++) {
firstRuleSet = factory.getOWLObjectIntersectionOf(currRuleset.get(i).getRuleList(currCls))
unionSet.add(firstRuleSet);
}
totalUnion = factory.getOWLObjectUnionOf(unionSet);
unionSet.clear()
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(owlCls, totalunion));
}
manager.saveOntology(ontology);