新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Semantic Web(语义Web,语义网或语义万维网, Web 3.0)及相关理论,如:Ontology(本体,本体论), OWL(Web Ontology Langauge,Web本体语言), Description Logic(DL, 描述逻辑),RDFa,Ontology Engineering等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区W3CHINA.ORG讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → 各位大侠求助啊[求助] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 10885 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 各位大侠求助啊[求助] 举报  打印  推荐  IE收藏夹 
       本主题类别: Ontology Language | RDF/RDFS    
     led19880901 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:57
      门派:XML.ORG.CN
      注册:2011/1/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给led19880901发送一个短消息 把led19880901加入好友 查看led19880901的个人资料 搜索led19880901在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看led19880901的博客楼主
    发贴心情 各位大侠求助啊[求助]

    大家好,我是新手,现在想用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 -->



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


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/4/25 16:18:00
     
     led19880901 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:57
      门派:XML.ORG.CN
      注册:2011/1/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给led19880901发送一个短消息 把led19880901加入好友 查看led19880901的个人资料 搜索led19880901在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看led19880901的博客2
    发贴心情 
    附件分别是protege中和我自己用jena解析出来的类树结构,有几个类就是没有出来,我调试的时候也看过了,对thing进行listsubclasses之后就出来了三个类,而实际有五个啊应该。。。。
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/4/25 16:21:00
     
     ledful 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:9
      积分:88
      门派:XML.ORG.CN
      注册:2011/4/7

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给ledful发送一个短消息 把ledful加入好友 查看ledful的个人资料 搜索ledful在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问ledful的主页 引用回复这个贴子 回复这个贴子 查看ledful的博客3
    发贴心情 
    看不懂

    ----------------------------------------------
    LED Display www.ledful.com

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/5/18 16:10:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/26 4:44:10

    本主题贴数3,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    171.875ms