以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  【求助】用jena将protege好的本体导入数据库出现的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=87453)


--  作者:newnewz
--  发布时间:11/3/2010 8:39:00 PM

--  【求助】用jena将protege好的本体导入数据库出现的问题
在Eclipse中使用jena将本体存入书库,就是用论坛中大家分享的代码
import java.io.*;
import java.sql.SQLException;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;


public class Ontology{
     public static final String strDriver ="com.mysql.jdbc.Driver"; // path of driver class
     public static final String strURL ="jdbc:mysql://localhost/ontology"; // URL of database
     public static final String strUser ="root"; // database user id
     public static final String strPassWord ="mysql"; // database password
     public static final String strDB="MySQL"; // database type

     public static void main(String[] args){
         try{// 创建一个数据库连接
              IDBConnection conn = new DBConnection ( strURL, strUser, strPassWord, strDB );
            // 加载数据库驱动类,需要处理异常
              try{
                   Class.forName(strDriver);
              }catch(ClassNotFoundException e) {
                   System.out.println("ClassNotFoundException, Driver is not available...");
              }
            // 使用数据库连接参数创建一个模型制造器
              ModelMaker maker = ModelFactory.createModelRDBMaker(conn);
              // 创建一个默认模型,命名为 MyOntology
              Model defModel = maker.createModel("MyOntology");
              // 准备需要存入数据库的本体文件,建立输入文件流
              FileInputStream inputStreamfile = null;
              try {
                   File file = new File("C:\\Expert.rdf-xml.owl");
                   inputStreamfile = new FileInputStream(file);
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
                   System.out.println("Ontology File is not available...");
              }
              InputStreamReader in = null;
              try {
                   in = new InputStreamReader(inputStreamfile, "UTF-8");
              } catch (UnsupportedEncodingException e) {
                   e.printStackTrace();
              }
            // 读取文件
            defModel.read(in,null);
            // 关闭输入流读取器
            try {
                   in.close();
              } catch (IOException e) {
                   e.printStackTrace();
              }
              // 执行数据转换,将本体数据存入数据库
            defModel.commit();
            
            // 关闭数据库连接
              try {
                   conn.close();
              } catch (SQLException e) {
                   e.printStackTrace();
              }
         }catch(RDFRDBException e){
          e.printStackTrace(System.out);
              System.out.println("Exceptions occur...");
         }
     }
}
运行后出现这样的错误
Usage:
  java jena.schemagen [options ...]

Commonly used options include:
   -i <input> the source document as a file or URL.
   -n <name> the name of the created Java class.
   -a <uri> the namespace URI of the source document.
   -o <file> the file to write the generated class into.
   -o <dir> the directory in which the generated Java class is created.
            By default, output goes to stdout.
   -e <encoding> the encoding of the input document (N3, RDF/XML, etc).
   -c <config> a filename or URL for an RDF document containing
               configuration parameters.

Many other options are available. See the schemagen HOWTO in the
Jena documentation for full details.
是什么意思啊 怎么解决啊
请大家帮忙啊 谢谢啦!


--  作者:laotao
--  发布时间:11/4/2010 9:57:00 AM

--  
在哪一行上出错的呢?

model.read好像不能解析owl格式的文件, 另存为rdf格式的试试


--  作者:newnewz
--  发布时间:11/4/2010 5:25:00 PM

--  
谢谢啦,问题已经解决啦
--  作者:描述逻辑新手
--  发布时间:11/16/2010 2:52:00 PM

--  您好,您怎么解决的呢
您好,我也出现这个错误,怎么解决呢
--  作者:newnewz
--  发布时间:11/22/2010 6:06:00 PM

--  
我不知道你是怎么运行的,记得我当时出现那个错误是因为我是直接点击工具栏那个运行按钮运行的,我们实验室的一个说那样可能找不到main函数而出现那个错误,后来我是右击Eclipse左侧那个列表中相应文件,然后选择运行,我的这样就好了。不知道你的是那种情况。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms