如何将嵌入的 Blazegraph 内容转储到 RDF 文件? [英] How can I dump embedded Blazegraph contents to an RDF file?

查看:57
本文介绍了如何将嵌入的 Blazegraph 内容转储到 RDF 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Scala 中创建了一个 blazegraph RDF4J 存储库和连接:

I have created a blazegraph RDF4J repository and connection in Scala:

val props = new Properties()
props.put(Options.BUFFER_MODE, BufferMode.DiskRW)
props.put(Options.FILE, "embedded.jnl")
var sail = new BigdataSail(props)
var repo = new BigdataSailRepository(sail)
repo.initialize()
var cxn = repo.getConnection()

我可以添加语句、检索 SPARQL 结果等

I can add statements, retrieve SPARQL results, etc.

现在我想将存储库的内容转储到 RDF 文件中,like这个:

Now I'd like to dump the contents of the repository to an RDF file, like this:

Rio.write(model, System.out, RDFFormat.RDFXML);

但是如果我尝试用我的 cxnrepo 替换预期的模型参数,Eclipse 会抱怨:

But if I try to substitute my cxn or repo for the expected model argument, Eclipse complains:

重载方法值写入替代:(x$1:Iterable[org.openrdf.model.Statement],x$2: java.io.Writer,x$3:org.openrdf.rio.RDFFormat) 单位 (x$1:Iterable[org.openrdf.model.Statement],x$2: java.io.OutputStream,x$3:org.openrdf.rio.RDFFormat)Unit 不能应用于(com.bigdata.rdf.sail.BigdataSailRepository, java.io.FileOutputStream,org.openrdf.rio.RDF 格式).

overloaded method value write with alternatives: (x$1: Iterable[org.openrdf.model.Statement],x$2: java.io.Writer,x$3: org.openrdf.rio.RDFFormat)Unit (x$1: Iterable[org.openrdf.model.Statement],x$2: java.io.OutputStream,x$3: org.openrdf.rio.RDFFormat)Unit cannot be applied to (com.bigdata.rdf.sail.BigdataSailRepository, java.io.FileOutputStream, org.openrdf.rio.RDFFormat).

我如何从存储库和连接获得 Rio.write() 预期的模型?或者我可以用其他方式转储三元组吗?

How do I get from the repo and connection that I have to a model expected by Rio.write()? Or can I dump the triples in some other way?

推荐答案

这里有很好的描述 http://docs.rdf4j.org/programming/ 点 3.2.8.使用 RDFHandlers

It is quite nicely described here http://docs.rdf4j.org/programming/ point 3.2.8. Using RDFHandlers

import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFWriter;

try (RepositoryConnection conn = repo.getConnection()) {
RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, System.out);
conn.prepareGraphQuery(QueryLanguage.SPARQL,
   "CONSTRUCT {?s ?p ?o } WHERE {?s ?p ?o } ").evaluate(writer);
}

而不是 System.out 写入文件.

And instead of System.out write to a file.

这篇关于如何将嵌入的 Blazegraph 内容转储到 RDF 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆