以文本方式查看主题

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


--  作者:oynwj
--  发布时间:11/21/2007 9:06:00 PM

--  求助:这段程序错哪了?
请教各位高手,我在Eclipse里运行下面这段程序,为什么总是“无法打开本体文件,程序将终止”,怎么错了呢?
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;

public class Jena {

 /**
  * @param args
  */
 public String filepath="d\\ktbg\\R9.rdf-xml.owl";
 Model model;
 public Jena(){
      model=ModelFactory.createDefaultModel();
      loadmodel();      
 }
    public boolean runQuery(String queryStr){
     Query query=QueryFactory.create(queryStr);
     QueryExecution qe=QueryExecutionFactory.create(query,model);
     ResultSet results=qe.execSelect();
     while (results.hasNext()){
      QuerySolution soln=results.nextSolution();
      System.out.print(soln.get("s").toString());
      System.out.print("\t");
      System.out.print(soln.get("p").toString());
      System.out.print("\t");
      System.out.print(soln.get("o").toString());
      System.out.println("\n");
      }
     results =null;
     qe.close();
     return true;
    }
    private void loadmodel(){
     InputStreamReader in;
     try{
      FileInputStream file = new FileInputStream(filepath);
      in=new InputStreamReader(file,"UTF-8");
      model.read(in,null);
      String rule = "[owl:inverseOf: (?pa owl:inverseOf ?pb) (?a ?pa ?b)->(?b ?pb ?a)]";
      Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rule));
      model = ModelFactory.createInfModel(reasoner, model);
      in.close();
     }catch (FileNotFoundException e){
      System.out.println("无法打开本体文件,程序将终止");
      System.exit(0);
     }catch (IOException e){
         e.printStackTrace();
         System.exit(0);     
     }
    }
    public static void main(String[] args){
     Jena myLearn = new Jena();
     String queryStr = "Select ?s ?p ?o where{?s ?p ?o.}";
     myLearn.runQuery(queryStr );
    }
}
谢谢指教!


--  作者:nihao620
--  发布时间:11/21/2007 9:41:00 PM

--  
public String filepath="d\\ktbg\\R9.rdf-xml.owl";

你把"d\\ktbg\\R9.rdf-xml.owl"改成"d:\\ktbg\\R9.rdf-xml.owl"试试

也可以把这个文件放在当前文件夹下,用"file:R9.rdf-xml.owl"来表示


--  作者:oynwj
--  发布时间:11/22/2007 12:16:00 PM

--  
谢谢楼上的朋友,原来是这个问题,呵呵,我的智商太低了
--  作者:nihao620
--  发布时间:11/23/2007 3:28:00 PM

--  
呵呵
不要这样说,大家都是一样的,以后小心一点就可以了.
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms