【发布时间】:2014-09-16 09:46:55
【问题描述】:
我有一个问题要问你:
我已经在 TDB 三重存储中加载了我的文件 RDF:
Dataset dataset = TDBFactory.createDataset(directory);
Model model = dataset.getNamedModel("http://nameFile");
TDBLoader.loadModel(model, file );
现在,我想实现一个检查图形是否在三重存储上的过程。
我已经写了这段代码:
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);
}
我已经看到此代码因以下错误而失败:
线程“main”java.lang.UnsupportedOperationException 中的异常:Quad:主题不能为空
在 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)
在 com.hp.hpl.jena.tdb.lib.TupleLib.access$100(TupleLib.java:45)
在 com.hp.hpl.jena.tdb.lib.TupleLib$4.convert(TupleLib.java:87)
在 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)
我在这一行收到此错误:
Statement statement = stmti.nextStatement();
特别是,我已经看到将许多这种类型的三元组加载到三元组存储中(代替其他三元组):
s: null p: http://www.w3.org/2000/01/rdf-schema#label o: null
但是,我的 RDF 文件没有这些三元组!为什么要加载这些三元组?
【问题讨论】:
-
你在哪里初始化results?
-
对不起,我忘了复制一部分。我已经编辑了我的帖子
-
问题是当我读取模型时(Model model = dataset.getNamedModel("nameFile");)。你能帮帮我吗?
-
出现错误的确切行是哪一行?您还需要确保加载的数据是正确的。
-
我在这一行得到错误:Statement statement = stmti.nextStatement();
标签: java rdf jena triplestore tdb