在TDB Triple Store中加载RDF Triple时出错 [英] Error when I load RDF triples in TDB Triple Store
问题描述
我有一个问题要问你
我已将文件RDF加载到TDB Triple Store中:
I have loaded my file RDF in TDB Triple Store:
Dataset dataset = TDBFactory.createDataset(directory);
Model model = dataset.getNamedModel("http://nameFile");
TDBLoader.loadModel(model, file );
现在,我想实现一个检查图形是否在三重存储中的过程.
Now, I would like to realize a procedure which checks whether the graph is on the Triple Store or not.
我已经编写了这段代码:
I have written this code:
String queryStr = "select * {graph <http://nameFile> { ?s ?p ?o }}";
Dataset dataset = TDBFactory.createDataset(directory);
Query query = QueryFactory.create(queryStr);
QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
qexec.getContext().set(TDB.symUnionDefaultGraph, true);
/*Execute the Query*/
ResultSet results = qexec.execSelect();
if (!results.hasNext()) {
Model model = dataset.getNamedModel("http://nameFile");
TDBLoader.loadModel(model, label);
} else {
Model model = dataset.getNamedModel("http://nameFile");
}
StmtIterator stmti = model.listStatements();
while (stmti.hasNext()) {
Statement statement = stmti.nextStatement();
System.out.println(statement);
}
我已经看到此代码因以下错误而失败:
I have seen that this code fails with this error:
线程"main"中的异常java.lang.UnsupportedOperationException:Quad:主题不能为空
Exception in thread "main" java.lang.UnsupportedOperationException: Quad: subject cannot be null
com.hp.hpl.jena.sparql.core.Quad.(Quad.java:62)
位于com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:162)
位于com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:153)
at com.hp.hpl.jena.tdb.lib.TupleLib.access $ 100(TupleLib.java:45)
at com.hp.hpl.jena.tdb.lib.TupleLib $ 4.convert(TupleLib.java:87)
at com.hp.hpl.jena.tdb.lib.TupleLib $ 4.convert(TupleLib.java:83)
在org.apache.jena.atlas.iterator.Iter $ 4.next(Iter.java:322)
在org.apache.jena.atlas.iterator.Iter $ 4.next(Iter.java:322)
在org.apache.jena.atlas.iterator.Iter.next(Iter.java:920)
在com.hp.hpl.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
位于com.hp.hpl.jena.util.iterator.Map1Iterator.next(Map1Iterator.java:45)
在com.hp.hpl.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
在com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl.next(StmtIteratorImpl.java:42)
在com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl.nextStatement(StmtIteratorImpl.java:52)
at com.hp.hpl.jena.sparql.core.Quad.(Quad.java:62)
at com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:162)
at com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:153)
at com.hp.hpl.jena.tdb.lib.TupleLib.access$100(TupleLib.java:45)
at com.hp.hpl.jena.tdb.lib.TupleLib$4.convert(TupleLib.java:87)
at com.hp.hpl.jena.tdb.lib.TupleLib$4.convert(TupleLib.java:83)
at org.apache.jena.atlas.iterator.Iter$4.next(Iter.java:322)
at org.apache.jena.atlas.iterator.Iter$4.next(Iter.java:322)
at org.apache.jena.atlas.iterator.Iter.next(Iter.java:920)
at com.hp.hpl.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
at com.hp.hpl.jena.util.iterator.Map1Iterator.next(Map1Iterator.java:45)
at com.hp.hpl.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
at com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl.next(StmtIteratorImpl.java:42)
at com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl.nextStatement(StmtIteratorImpl.java:52)
我在此行收到此错误:
Statement statement = stmti.nextStatement();
尤其是,我已经看到将许多这种类型的三元组(替代其他三元组)加载到三元组存储中:
In particular, I've seen that are loaded into the triple store many triples of this type (in substitution of others):
s:null p: http://www.w3.org/2000/01/rdf-schema#label o:空
但是,我的RDF文件没有这些三元组!为什么要加载这些三元组?
but, my RDF file don't have these triples! Why these triples are loaded?
推荐答案
我猜想用于数据加载的代码是在与查询代码不同的程序中运行的.如果是这样,那么
I guess the code for data loading is run in a different program to the query code. If so, then
TDB.sync(dataset)
(使用事务会更好,或者使用命令行工具进行批量加载).
(using transactions would be better, or use the command line tool to do a bulk load).
这篇关于在TDB Triple Store中加载RDF Triple时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!