TDB 耶拿查询
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该是你的 CLASSPATH 的问题,当我使用 TDB 时,我有以下脚本将 Jena-TDB 库加载到我的类路径中。
它是 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 ..
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 completejava.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 isowl:sameAs
.