以文本方式查看主题

-  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=90578)


--  作者:led19880901
--  发布时间:4/25/2011 4:18:00 PM

--  各位大侠求助啊[求助]
大家好,我是新手,现在想用jena解析owl文件显示类的结构树。思路就是获取thing类,然后通过迭代遍历子类来构建类树结构。代码如下:
        public Node getTreeRoot(String owlPath, String url) {
  // 创建本体模型
  OntModel ontModel = ModelFactory
    .createOntologyModel(OntModelSpec.OWL_MEM,null);
  ontModel.read("file:" + owlPath); // 读取文件,加载模型
  
  OntClass oc = ontModel.getOntClass(url + "Thing");
  preOrder(oc, root);

  return root;
 }

 public void preOrder(OntClass c, Node node) {
  // 如果传进来的节点不为空,则遍历,注,叶子节点的子节点为null
  if (!c.isAnon()) {
   node.setId(i);
   i++;
   node.setText(c.getModel().getGraph().getPrefixMapping().shortForm(
     c.getURI()));
   node.setIcon("images/icon.png");
   if (c.hasSubClass()) {
    node.setLeaf(false);
    for (Iterator it = c.listSubClasses(); it.hasNext();) {
     OntClass sb = (OntClass) it.next();
     Node snode = new Node();
     node.getChildren().add(snode);
     preOrder(sb, snode);
    }
   } else {
    node.setLeaf(true);
   }
  }
 }

我自定义了一个node类用来存放节点,有如下属性:
        private int id;
 private String text;
 private boolean leaf;
 private String icon;
 private List<Node> children = new ArrayList<Node>();

前台的树控件用的是extjs的tree组件,现在的问题就是根据thing类listsubclasses后没有取到所有的子类,只取到部分,调了好几天了都不知道问题所在,实在头痛,麻烦高手帮个忙了。

owl文件是用protege创建的,如下:
<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
    xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
    xmlns="http://www.owl-ontologies.com/Ontology1295491584.owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://www.owl-ontologies.com/Ontology1295491584.owl">
  <owl:Ontology rdf:about=""/>
  <owl:Class rdf:ID="Camera">
    <rdfs:subClassOf>
      <owl:Class rdf:ID="Electronic_Product"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:ID="Mobile_Phone">
    <rdfs:subClassOf>
      <owl:Class rdf:about="#Electronic_Product"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:ID="Company"/>
  <owl:Class rdf:ID="Administrator">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="edit"/>
        </owl:onProperty>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Electronic_Product"/>
        </owl:someValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Electronic_Product"/>
        </owl:someValuesFrom>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="delete"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Electronic_Product"/>
        </owl:someValuesFrom>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="add"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Class rdf:ID="User"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:ID="Game_Player">
    <rdfs:subClassOf>
      <owl:Class rdf:about="#Electronic_Product"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:ID="Shop">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="sell"/>
        </owl:onProperty>
        <owl:allValuesFrom>
          <owl:Class rdf:ID="Product"/>
        </owl:allValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </owl:Class>
  <owl:Class rdf:ID="Area"/>
  <owl:Class rdf:about="#User">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="searh"/>
        </owl:onProperty>
        <owl:allValuesFrom rdf:resource="#Product"/>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </owl:Class>
  <owl:Class rdf:ID="Provider">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Product"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="provide"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </owl:Class>
  <owl:Class rdf:ID="Earphone">
    <rdfs:subClassOf>
      <owl:Class rdf:about="#Electronic_Product"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:ID="VIP_Customer">
    <rdfs:subClassOf>
      <owl:Class rdf:ID="Customer"/>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="#Customer">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="add_into_shopcart"/>
        </owl:onProperty>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Electronic_Product"/>
        </owl:someValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="add_into_favorites"/>
        </owl:onProperty>
        <owl:someValuesFrom>
          <owl:Class rdf:about="#Electronic_Product"/>
        </owl:someValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#User"/>
  </owl:Class>
  <owl:Class rdf:about="#Electronic_Product">
    <rdfs:subClassOf rdf:resource="#Product"/>
  </owl:Class>
  <owl:Class rdf:ID="MP4">
    <rdfs:subClassOf rdf:resource="#Electronic_Product"/>
  </owl:Class>
  <owl:Class rdf:ID="Mobile_Storage">
    <rdfs:subClassOf rdf:resource="#Electronic_Product"/>
  </owl:Class>
  <owl:Class rdf:ID="Computer">
    <rdfs:subClassOf rdf:resource="#Electronic_Product"/>
  </owl:Class>
  <owl:Class rdf:ID="MP3">
    <rdfs:subClassOf rdf:resource="#Electronic_Product"/>
  </owl:Class>
  <owl:Class rdf:ID="Normal_Customer">
    <rdfs:subClassOf rdf:resource="#Customer"/>
  </owl:Class>
  <owl:Class rdf:ID="Electronic_Book">
    <rdfs:subClassOf rdf:resource="#Electronic_Product"/>
  </owl:Class>
  <owl:Class rdf:ID="Electronic_Shop">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:allValuesFrom rdf:resource="#Electronic_Product"/>
        <owl:onProperty>
          <owl:ObjectProperty rdf:ID="main_sell"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="#Shop"/>
  </owl:Class>
  <owl:ObjectProperty rdf:about="#provide">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#Provider"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#main_sell">
    <rdfs:subPropertyOf>
      <owl:ObjectProperty rdf:about="#sell"/>
    </rdfs:subPropertyOf>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#add_into_shopcart">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#Customer"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#edit">
    <rdfs:domain rdf:resource="#Administrator"/>
    <rdfs:range rdf:resource="#Product"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#add_into_favorites">
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:range rdf:resource="#Product"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#sell">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#Shop"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#searh">
    <rdfs:domain rdf:resource="#User"/>
    <rdfs:range rdf:resource="#Product"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#add">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#Administrator"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="#delete">
    <rdfs:domain rdf:resource="#Administrator"/>
    <rdfs:range rdf:resource="#Product"/>
  </owl:ObjectProperty>
  <owl:DatatypeProperty rdf:ID="color">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:ID="date">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
    <rdfs:domain rdf:resource="#Product"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:ID="price">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
    <rdfs:domain rdf:resource="#Product"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:ID="stock">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
    <rdfs:domain rdf:resource="#Product"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:ID="name">
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
  </owl:DatatypeProperty>
  <owl:DatatypeProperty rdf:ID="discount">
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
  </owl:DatatypeProperty>
</rdf:RDF>

<!-- Created with Protege (with OWL Plugin 3.4.4, Build 579)  http://protege.stanford.edu -->



此主题相关图片如下:
按此在新窗口浏览图片
此主题相关图片如下:
按此在新窗口浏览图片


--  作者:led19880901
--  发布时间:4/25/2011 4:21:00 PM

--  
附件分别是protege中和我自己用jena解析出来的类树结构,有几个类就是没有出来,我调试的时候也看过了,对thing进行listsubclasses之后就出来了三个类,而实际有五个啊应该。。。。
--  作者:ledful
--  发布时间:5/18/2011 4:10:00 PM

--  
看不懂
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
7,250.000ms