【问题标题】:Pellet + Transitivity + Reason + OWL-APIPellet + 传递性 + Reason + OWL-API
【发布时间】:2016-02-07 08:50:59
【问题描述】:

我在使用 Pellet 推断传递对象属性时遇到问题 Similarto。我有个人 A Similarto B 和个人 B Similarto C。我想在 OWL API 中使用 Pellet 或使用 Jena 来获取个人组 A、B、C,但我无法弄清楚在 OWL API 中进行推理的代码。

我已经在 OWL API 中加载了本体,是否有一个示例代码可以推断一组具有相同传递属性的个体?

【问题讨论】:

  • 或者Pellet不能做到这一点?有人可以帮忙吗?

标签: jena owl ontology owl-api pellet


【解决方案1】:

这个答案是由 Ignazio Palmisano 指示的:

如果颗粒没有当前的解决方案,我们可以自己编写。

  • 选择你的起点,即你的第一个人 传递链
  • 检索您所关注的属性的所有填充符
  • 对于每个填充物,像上一步一样检索所有填充物
  • 注意避免循环

(同时拥有集合和列表的原因是能够迭代 一种可预测的方式,同时添加元素,并保持快速遏制 检查 - 以一点内存为代价)

 OWLDataFactory factory = manager.getOWLDataFactory();
            Set<OWLNamedIndividual> found= new HashSet<>(); 
            List<OWLNamedIndividual> list= new ArrayList<>();
            List<OWLNamedIndividual> SeaIcelist= new ArrayList<>();
            PrefixManager pm = new DefaultPrefixManager("http://www.semanticweb.org/SeaIceOntology#");

            OWLNamedIndividual root = factory.getOWLNamedIndividual(":thickness", pm);
            OWLObjectProperty p = factory.getOWLObjectProperty(IRI
                    .create("http://www.semanticweb.org/SeaIceOntology#similarTo")); 
            OWLReasoner r= new StructuralReasonerFactory().createNonBufferingReasoner(loadMODIS);

            found.add(root); 
            list.add(root); 


            while(i < list.size()){ 
                for(Node<OWLNamedIndividual> ind:r.getObjectPropertyValues
                        (list.get(i), (OWLObjectPropertyExpression)p)){ 
                    for(OWLNamedIndividual nind:ind){
                        if(found.add(nind)){
                            list.add(nind);
                            /* select specific individuals to the SeaIcelist */
                            for(OWLClassExpression ex : nind.getTypes(loadMODIS)) {
                                while(ex.asOWLClass().getSuperClasses(loadMODIS).iterator().hasNext()){
                                    for(OWLClassExpression cl:ex.asOWLClass().getSuperClasses(loadMODIS)) {
                                        if (cl.equals(factory.getOWLClass
                                                (IRI.create("http://www.semanticweb.org/SeaIceOntology#EarthScienceProperty"))) ){
                                            SeaIcelist.add(nind);
                                            break;
                                        }
                                    }
                                    ex = ex.asOWLClass().getSuperClasses(loadMODIS).iterator().next();
                                }
                             }
                            /* select specific individuals to the SeaIcelist */
                        }
                    }
                }
                i ++;
            }

            for (int j = 1; j < i; j ++){
                System.out.println("These are all the terms which has similar meanings." + list.get(j).toStringID());
            }

            int size = SeaIcelist.size();
            for (int j = 0; j < size; j ++){
                System.out.println("These are all the standard terms which has similar meanings." + SeaIcelist.get(j).toStringID());
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    相关资源
    最近更新 更多