以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (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=73437)


--  作者:changwl
--  发布时间:3/23/2009 11:29:00 PM

--  帮忙看下程序错在哪呢,谢谢了哦!!
[U]
此主题相关图片如下:
按此在新窗口浏览图片
这是在protege中做的Animal。程序为:
package cn.edu.Animal;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.ontology.*;
import java.util.Iterator;
public class TryOntology {
public static void main(String[] args) {
     // 创建本体模型
   OntModel ontModel = ModelFactory.createOntologyModel();
     ontModel.read("file:D:\\Program Files\\Protege_3.4_rc1\\newAnimal.owl");
    // 迭代显示模型中的类
   for (Iterator i = ontModel.listClasses(); i.hasNext();)
         {
           OntClass c = (OntClass) i.next();
           if (!c.isAnon()) // 如果不是匿名类
           { System.out.print("Class");
                   // 获取类的URI并输出,在输出时对URI做了简化(将命名空间前缀省略)
             System.out.println(c.getModel().getGraph().getPrefixMapping   ().shortForm(c.getURI()));
               // 迭代显示当前类的父类
           for (Iterator it = c.listSuperClasses(); it.hasNext();)
                {
                   OntClass sp = (OntClass) it.next();
                   String str = c.getModel().getGraph().getPrefixMapping().shortForm(c.getURI())+ "'s superClass is " ;
                   String strSP = sp.getURI();
                   try{ // 另一种简化处理URI的方法
                 str = str + ":" + strSP.substring(strSP.indexOf('#')+1);
                         System.out.println("  Class" +str);
                       }
                   catch( Exception e ){ }
                 }

               // 迭代显示当前类的子类
          for (Iterator it = c.listSubClasses(); it.hasNext();)
               {
                System.out.print("  Class");
                OntClass sb = (OntClass) it.next();
                System.out.println(c.getModel().getGraph().getPrefixMapping().shortForm(c.getURI())+ "'s suberClass is "+ sb.getModel().getGraph().getPrefixMapping() .shortForm(sb.getURI()));
               }
               // 迭代显示与当前类相关的所有属性
          for(Iterator ipp = c.listDeclaredProperties(); ipp.hasNext();)
               {
                OntProperty p = (OntProperty)ipp.next();
                 System.out.println("  associated property: " + p.getLocalName());
                }
              }
           }
         }
  }
其运行结果是:
Class:Tree
  Class:Tree's superClass is :Plant
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Carnivore
  Class:Carnivore's suberClass is :Lion
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Lion
  Class:Lion's superClass is :Carnivore
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Animal
  Class:Animal's superClass is :Resource
  Class:Animal's suberClass is :Herbivore
  Class:Animal's suberClass is :Giraffe
  associated property: eated
  associated property: is_part_of
  associated property: eat
  associated property: Belonging
  associated property: maineat
Class:Branch
  Class:Branch's superClass is :Plant
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Herbivore
  Class:Herbivore's superClass is :Animal
  Class:Herbivore's superClass is :Resource
  Class:Herbivore's suberClass is :Giraffe
  associated property: eated
  associated property: is_part_of
  associated property: eat
  associated property: Belonging
  associated property: maineat
Class:Giraffe
  Class:Giraffe's superClass is :Herbivore
  Class:Giraffe's superClass is :Resource
  Class:Giraffe's superClass is :Animal
  associated property: eated
  associated property: is_part_of
  associated property: eat
  associated property: Belonging
  associated property: maineat
Class:Plant
  Class:Plant's suberClass is :Tree
  Class:Plant's suberClass is :Branch
  Class:Plant's suberClass is :Leaf
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Leaf
  Class:Leaf's superClass is :Plant
  associated property: eated
  associated property: is_part_of
  associated property: maineat
Class:Zoo
  Class:Zoo's superClass is :Resource
  associated property: eated
  associated property: is_part_of
  associated property: Address
  associated property: Tel
  associated property: maineat
[/U]问题是:Carnivore没有输出其superclass:Animal。希望大家帮忙看看问题在哪呢?谢谢了哦!!


--  作者:jpz6311whu
--  发布时间:3/23/2009 11:37:00 PM

--  
请楼主将本体库owl文件贴出来看看
--  作者:jpz6311whu
--  发布时间:3/23/2009 11:38:00 PM

--  
请楼主将本体库owl文件贴出来看看
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms