virtuoso-opensource:使用jenaprovider,如何从文件而不是从URL读取数据?

时间:2015-02-25 11:19:05

标签: java rdf virtuoso

使用jena providervirtuoso加载来自网址的数据非常简单。以下代码完成了这项工作:

    VirtGraph graph = new VirtGraph ("foaf", "jdbc:virtuoso://localhost:1111", "dba", "dba");

/*      Load data to Virtuoso       */

    System.out.print ("Begin read from 'http://xmlns.com/foaf/0.1/index.rdf'  ");
    graph.read("http://xmlns.com/foaf/0.1/index.rdf", "RDF/XML");

但是,当您想从本地文件加载它们时,情况会有所不同。我试过这个:

    VirtGraph graph = new VirtGraph ("foaf", "jdbc:virtuoso://localhost:1111", "dba", "dba");

    graph.read("/tmp/index.rdf", "RDF/XML");
    graph.close();

但我最终得到以下例外:

com.hp.hpl.jena.shared.JenaException: virtuoso.jdbc4.VirtuosoException: HC001: Connection Error in HTTP Client

有人对如何使用jenaprovider从文件加载rdf有任何线索吗?

配置设置 virt_jena2.jar virtjdbc4.jar

2 个答案:

答案 0 :(得分:1)

不是仅提供文件名,而是使用file URI。 E.g:

graph.read("file:///tmp/index.rdf", "RDF/XML");

答案 1 :(得分:1)

关于你的第一个例子:

VirtGraph graph = new VirtGraph ("foaf", "jdbc:virtuoso://localhost:1111", "dba", "dba");
graph.read("http://xmlns.com/foaf/0.1/index.rdf", "RDF/XML");

它被转换为下一个SPARQL命令(在服务器端执行 - Sources):

load "http://xmlns.com/foaf/0.1/index.rdf" into graph <foaf>

此命令不允许将本地文件加载到DBMS。 您可以使用Jena Model方法加载本地文件。像下一个(Jena Model reference):

  Model model = VirtModel.openDatabaseModel("load:test", "jdbc:virtuoso://localhost:1111", "dba", "dba");
  InputStream in = FileManager.get().open( nfile );
  if (in == null) {
      throw new IllegalArgumentException( "File: " + nfile + " not found");
  }
  model.read(new InputStreamReader(in), null, "N-TRIPLE");
  model.close();