如何使用 Jena TDB 存储链接电影数据库的本地版本
我有一个 N-Triples 格式的 LinkedMDB 本地版本,想要查询它。现在,我想使用Jena TDB,它可以存储可以用于以后查询的数据。我检查了 TDB Java API 文档,但无法加载 N- Triples 文件,然后使用 SPARQL 进行查询。我使用了以下代码:
String directory = "E:\\Applications\\tdb-0.8.9\\TDB-0.8.9\\bin\\tdb";
Dataset dataset = TDBFactory.createDataset(directory);
// assume we want the default model, or we could get a named model here
Model tdb = dataset.getDefaultModel();
// read the input file - only needs to be done once
String source = "E:\\Applications\\linkedmdb-18-05-2009-dump.nt";
FileManager.get().readModel( tdb, source, "N-TRIPLES" );
并得到以下异常
Exception in thread "main" com.hp.hpl.jena.tdb.base.file.FileException: Not a directory: E:\Applications\tdb-0.8.9\TDB-0.8.9\bin\tdb
at com.hp.hpl.jena.tdb.base.file.Location.<init>(Location.java:83)
at com.hp.hpl.jena.tdb.TDBFactory.createDataset(TDBFactory.java:79)
at tutorial.Temp.main(Temp.java:14)
I have a local version of LinkedMDB that is in N-Triples format and want to query it. Now, I want to use Jena TDB, which can store the data that can be used for querying later. I checked the documentation for TDB Java API, but was unable to load the N-Triples file and then query with SPARQL. I've used the following code:
String directory = "E:\\Applications\\tdb-0.8.9\\TDB-0.8.9\\bin\\tdb";
Dataset dataset = TDBFactory.createDataset(directory);
// assume we want the default model, or we could get a named model here
Model tdb = dataset.getDefaultModel();
// read the input file - only needs to be done once
String source = "E:\\Applications\\linkedmdb-18-05-2009-dump.nt";
FileManager.get().readModel( tdb, source, "N-TRIPLES" );
and got the following Exception
Exception in thread "main" com.hp.hpl.jena.tdb.base.file.FileException: Not a directory: E:\Applications\tdb-0.8.9\TDB-0.8.9\bin\tdb
at com.hp.hpl.jena.tdb.base.file.Location.<init>(Location.java:83)
at com.hp.hpl.jena.tdb.TDBFactory.createDataset(TDBFactory.java:79)
at tutorial.Temp.main(Temp.java:14)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 Java 读取 TDB 支持的模型非常简单,请参阅 TDB wiki 了解详细信息。例如,您可以:
正如 user205512 提到的,您可以在 Linux 或 Mac 上从命令行使用 tdbloader2,这对于大型 RDF 文件会更快。创建 TDB 索引后,您可以将文件复制到其他计算机。因此,您可以在 Linux 服务器上加载数据,然后将 tdb 目录中的所有文件发送到 Windows 计算机以继续开发。
要在 Windows 计算机上从命令行运行
tdbloader
,您需要类似 cygwin允许您运行 Unix 风格的脚本。您还需要设置环境变量TDBROOT
。Reading into a TDB-backed
Model
from Java is straightforward, see the TDB wiki for details. For example, you could:As user205512 mentioned, you can use
tdbloader2
from the command line on a Linux or Mac, which will be faster on large RDF files. Once the TDB indexes have been created, you can copy the files to other machines. So you can load the data on a Linux server, then ship all the files inside thetdb
directory to your Windows machine to continue development.To run
tdbloader
from the command line on your Windows machine, you'll need something like cygwin to allow you to run Unix-style scripts. You'll also need to set the environment variableTDBROOT
.您不需要任何 java 代码来执行此操作(
tdbloader2
更快):将加载 n-triple 文件。您可以使用以下方式查询:
有关 tdb 命令行工具的更多信息此处。
You don't need any java code to do this (
tdbloader2
is faster):will load in the n-triple file. You can query it using:
More information on the tdb command line tools here.
假设“nt格式”确实是“N-Triple”,那么Jena
Model.read(is, base, lang)
如果lang
为"N-Triple"
,方法将加载 N-Triple 格式。有关更多详细信息,请参阅Jena 教程文档。
Assuming that "nt format" is really "N-Triple", then the Jena
Model.read(is, base, lang)
method will load N-Triple format iflang
is"N-Triple"
.For more details, refer to the Jena tutorial document.