TDB 耶拿查询

发布于 2024-12-23 05:28:33 字数 1010 浏览 2 评论 0原文

我正在尝试使用 TDB 使用 Jena 在 Java 中进行查询。所以基本上我得到了一个 n3 文件名 Song.n3 并使用这个文件我想将它与 TDB 一起使用。因此,我创建了一个在 Java1 文件夹(Netbeans 项目文件夹)中生成的目录,然后我就有了实际 n3 文件的源代码。运行此代码后,出现错误“java.lang.NoClassDefFoundError”。基本上调试代码会导致错误由以下行引起:Dataset dataset = TDBFactory.createDataset(directory);。我不太清楚为什么会导致这个错误,可能是因为我的目录是空的,没有模型。

public static void main(String[] args) throws IOException {
   String directory = "./tdb";
   Dataset dataset = TDBFactory.createDataset(directory);
   Model tdb = dataset.getDefaultModel();
   String source = "C:\\Users\\Name\\Documents\\NetBeansProjects\\Java1\\src\\song.n3";
   FileManager.get().readModel( tdb, source, "N3" );
   String queryString = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?x owl:sameas ?y }";

   Query query = QueryFactory.create(queryString);

   QueryExecution qe = QueryExecutionFactory.create(query, tdb);
   ResultSet results = qe.execSelect();

   ResultSetFormatter.out(System.out, results, query);

   qe.close();
 }
}

I am trying to query in Java with Jena using TDB. So basically i got an n3 file name song.n3 and using this file I want to use this with TDB. So I have created a directory which is generated in my Java1 folder (Netbeans project folder) and then I have the source of the actual n3 file. After running this code I am having the error "java.lang.NoClassDefFoundError". Basically debugging the code lead to the error being caused by the line : Dataset dataset = TDBFactory.createDataset(directory);. I am not too sure why this error is caused could it be that it because my directory is empty with no model.

public static void main(String[] args) throws IOException {
   String directory = "./tdb";
   Dataset dataset = TDBFactory.createDataset(directory);
   Model tdb = dataset.getDefaultModel();
   String source = "C:\\Users\\Name\\Documents\\NetBeansProjects\\Java1\\src\\song.n3";
   FileManager.get().readModel( tdb, source, "N3" );
   String queryString = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?x owl:sameas ?y }";

   Query query = QueryFactory.create(queryString);

   QueryExecution qe = QueryExecutionFactory.create(query, tdb);
   ResultSet results = qe.execSelect();

   ResultSetFormatter.out(System.out, results, query);

   qe.close();
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-12-30 05:28:33

这应该是你的 CLASSPATH 的问题,当我使用 TDB 时,我有以下脚本将 Jena-TDB 库加载到我的类路径中。

#!/bin/bash
CP="."
for i in ./TDB-0.8.9/lib/*.jar ; do
    CP=$CP:./TDB-0.8.9/lib/$i
done
export CLASSPATH=$CP

它是 bash,但很容易翻译成 Windows 脚本。最重要的是,确保 /lib/ 目录中的所有 jar 都位于 CLASSPATH 中。不管怎样,它会帮助你给出完整的java.lang.NoClassDefFoundError,其中显示了未找到的类,这会给你提示它缺少什么。可能有些日志库未在 jena 发行版中提供。

另外,请注意 owl:sameas 谓词。 SPARQL 和 RDF 区分大小写,正确的谓词是 owl:sameAs

This should be a problem with your CLASSPATH, when I use TDB I have the following script to load the Jena-TDB libraries into my classpath ..

#!/bin/bash
CP="."
for i in ./TDB-0.8.9/lib/*.jar ; do
    CP=$CP:./TDB-0.8.9/lib/$i
done
export CLASSPATH=$CP

It is bash but very easy to translate into a Windows script. Bottom line, make sure that all the jars in /lib/ directory are in the CLASSPATH. Anyway, it would help it you give the complete java.lang.NoClassDefFoundError where the class not found is shown, that would give you a hint of what it is missing. Probably some of the logging libs that are not shipped inside the jena distribution.

Also, watch out for that owl:sameas predicate. SPARQL and RDF are case sensitive and the correct predicate is owl:sameAs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文