如何使用Jena TDB存储链接电影数据库的本地版本 [英] How to use Jena TDB to store local version of Linked Movie Database

查看:294
本文介绍了如何使用Jena TDB存储链接电影数据库的本地版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地版本的LinkedMDB,它是N-Triples格式,想要查询它。现在,我想使用Jena TDB,它可以存储可以用于以后查询的数据。我检查了 TDB Java API文档,但无法加载N三重文件,然后使用SPARQL进行查询。我使用了以下代码:

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" );

并得到以下例外

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)


推荐答案

从以下网址阅读TDB支持的模型 Java非常简单,有关详细信息,请参阅 TDB wiki 。例如,您可以:

Reading into a TDB-backed Model from Java is straightforward, see the TDB wiki for details. For example, you could:

// open TDB dataset
String directory = "./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 = "path/to/input.nt";
FileManager.get().readModel( tdb, source, "N-TRIPLES" );

// run a query
String q = "select * where {?s ?p ?o} limit 10";
Query query = QueryFactory.create(q);
QueryExecution qexec = QueryExecutionFactory.create(query, tdb);
ResultSet results = qexec.execSelect();
... etc ...

正如用户提到的那样,你可以使用 tdbloader2 来自Linux或Mac上的命令行,在大型RDF文件上会更快。创建TDB索引后,您可以将文件复制到其他计算机。因此,您可以在Linux服务器上加载数据,然后将 tdb 目录中的所有文件发送到Windows计算机以继续开发。

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 the tdb directory to your Windows machine to continue development.

要从Windows机器上的命令行运行 tdbloader ,您需要类似 cygwin 允许你运行Unix风格的脚本。您还需要设置环境变量 TDBROOT

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 variable TDBROOT.

这篇关于如何使用Jena TDB存储链接电影数据库的本地版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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