2016-02-07 16 views
0

我在使用Pellet推斷傳遞對象屬性Similarto時遇到問題。我有單獨的A Similarto B和單獨的B Similarto C.我想在OWL API中使用Pellet,或者使用Jena來獲得單獨的組A,B,C,但我無法弄清楚在OWL API中進行推理的代碼。Pellet +傳遞性+原因+ OWL-API

我已經在OWL API中加載了本體,並且是否存在一個用相同的傳遞屬性來連接一組個體的示例代碼?

+0

或者這不能由Pellet完成?任何人都可以幫忙 –

回答

0

這個答案是從納齊奧西隆彭明盛指示:

如果從顆粒沒有當前的解決方案,我們可以寫我們自己的。

  • 選擇您 傳遞鏈的起點,即第一個人
  • 檢索您要後
  • 對於每種填料,檢索所有填料如在上一步
  • 財產的全部填料
  • 以避免週期

的護理(之所以具有兩個一組和列表是能夠遍歷在 而可預測的方式增加元素,並保留快速遏制 檢查 - 以一點存儲器爲代價)

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()); 
      }