以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  推理简单例子,供初学者学习。  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=84733)


--  作者:hoho19840130
--  发布时间:5/12/2010 5:09:00 PM

--  推理简单例子,供初学者学习。
废话不多说,直接发代码(会Protege API和Jena API一般都看的懂):
public static void main(String[] args) {
  //Protege API
  JenaOWLModel owlModel = ProtegeOWL.createJenaOWLModel();
  owlModel.getNamespaceManager().setDefaultNamespace("http://hello.com#");
  OWLNamedClass personClass = owlModel.createOWLNamedClass("Person");   
  OWLObjectProperty hasBrother = owlModel.createOWLObjectProperty("hasBrother");
  hasBrother.setDomain(personClass);
  //给hasBrother设定为transitive
        hasBrother.setTransitive(true);
      OWLIndividual jim = personClass.createOWLIndividual("jim");
      OWLIndividual tom = personClass.createOWLIndividual("tom");
      OWLIndividual john = personClass.createOWLIndividual("john");
      jim.addPropertyValue(hasBrother, tom);
      //jim.setPropertyValue(hasBrother, tom);
      tom.addPropertyValue(hasBrother, john);
  
//这个是找不到jim有兄弟john
     Iterator it_protege = jim.listPropertyValues(hasBrother);
      for(;it_protege.hasNext();){
       System.out.println("a:"+it_protege.next());
      }
  //把Progete Model 转为 Jena Model    
        OntModel model = owlModel.getOWLDLOntModel();
       //加入jena的mini推理机(jena对本体有3种推理机)
        OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MINI_RULE_INF,model);     
      Individual jim_jena = model2.getIndividual("http://hello.com#jim");
      Property hasBrother_jena = model2.getProperty("http://hello.com#hasBrother");
      //这个是可以找到jim有兄弟john
      Iterator it = jim_jena.listPropertyValues(hasBrother_jena);
      for(;it.hasNext();){
       System.out.println("a:"+it.next());
      }
      
 }
我想问下有没有高手可以不把Protege Model转换Jena Model就可以找到transitive属性的隐性的值,最好别用推理机。
--  作者:andyneo
--  发布时间:2/23/2011 10:17:00 PM

--  
如果有多个兄弟 如何获得剩余的几个兄弟的名字呢? 谢谢!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms