或者 OWL API 中的一些 AND 规则?

OR some AND rules in OWL API?

我似乎无法弄清楚如何对一组 AND (ObjectIntersectionOf) 规则进行 OR (ObjectUnionOf?)。在 protégé 中打开 OWL 文件时,我的代码生成的是规则 (has_difi_min some double[<= "184.84"^^double]) 和 (has_mean_ndvi some double[<= " 0.3428"^^double]), 等等。用分隔线分隔 "rulesets",如下面的屏幕截图所示。

我的 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。

编辑:谢谢 Ignazio! 我的 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);

您正在创建 unionSet 但未使用它。不要向 ontology 添加公理,而是将 firstRuleSet 添加到 unionSet,然后在主循环外创建一个等效的 class 公理,就在保存 ontology 之前.