2

我似乎无法弄清楚如何 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);
4

1 回答 1

0

您正在创建unionSet但没有使用它。不是向本体添加公理,而是添加firstRuleSetto unionSet,然后在保存本体之前在主循环之外创建等效的类公理。

于 2015-07-16T20:04:40.617 回答