以文本方式查看主题

-  计算机科学论坛  (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=30075)


--  作者:mahongfu
--  发布时间:4/6/2006 3:43:00 PM

--  帮忙调试个程序!!!!
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("D:\\jena\\OBC\\sars.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
  }
}

帮忙调调这个程序!!
3ks


--  作者:tomfang
--  发布时间:4/6/2006 4:40:00 PM

--  
给出你的sars.owl以及process2.owl文件
--  作者:mahongfu
--  发布时间:4/6/2006 7:28:00 PM

--  
不好意思:下面的那个注解了。
model.read("file:\\C:\\Borland\\readEngineeRDF\\readEngineeRDF\\ontology\\process2.owl");

改成: model.read(new FileInputStream("C:\\Borland\\readEngineeRDF\\readEngineeRDF\\ontology\\process2.owl"),"");
         // model.read("file:\\C:\\Borland\\readEngineeRDF\\readEngineeRDF\\ontology\\process2.owl");

要不我重新发个帖子吧,这个没有办法上传。


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