以文本方式查看主题

-  中文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=30103)


--  作者:mahongfu
--  发布时间:4/6/2006 7:33:00 PM

--  调试程序(修改后)
package readengineerdf;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.ontology.*;


public class guhuazhen
{

  public static void main(String [] args)
  {
    OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );

                  try
              {
                          //FileInputStream a=new FileInputStream("sars.owl");
          model.read(new FileInputStream("C:\\Borland\\readEngineeRDF\\readEngineeRDF\\ontology\\process2.owl"),"");
         // model.read("file:\\C:\\Borland\\readEngineeRDF\\readEngineeRDF\\ontology\\process2.owl");
              }
              catch(IOException e)
              {
                  System.err.println(e.toString());
              }
              //the class number
              int j=0;


              //list classes
              for(Iterator i=model.listClasses();i.hasNext();)
              {

                   //the subclass string
                  String strSub="";
                  j++;
              OntClass c = (OntClass) i.next();
              String strClass=c.getModel().usePrefix(c.getURI());
              // getModel的作用是Return the model associated with this resource
              //usePrefix方法所在的位置doc\javadoc\com\hp\hpl\jena\shared\PrefixMapping.html
              strClass=strClass.substring(1);
              System.out.println(j+strClass);

              //to list sub-classes for each class

              for(Iterator k=c.listSubClasses(true);k.hasNext();)
              {
                  //这里列出直接的subclass
                  System.out.print("  "+"hasSubClass");
                  OntClass subclass=(OntClass)k.next();
                  //OntClass的作用是Interface that represents an ontology node
                  //characterising a class description
                  String strSubClass=subclass.getModel().usePrefix(subclass.getURI());

                  strSubClass=strSubClass.substring(1);
                  System.out.println(strSubClass);
                  strSub+=strSubClass+" ";
                  try
                  {
                          Statement stmRelation=conn.createStatement();
                          String strsql="insert into relation values ('"+strClass+"','"+strSubClass+"',"+"'hasSubClass')";
                          stmRelation.execute(strsql);
                          stmRelation.close();
                  }
                  catch(Exception ex)
                  {
                          ex.printStackTrace();
                  }
              }//end of class for
  }
}


}


--  作者:mahongfu
--  发布时间:4/6/2006 8:08:00 PM

--  
哦,要不你自己找个owl文件试试。这个主要是程序的问题。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms