在TDB Triple Store中加载RDF三元组时出错

我有一个问题问你:

我在TDB Triple Store中加载了我的文件RDF:

Dataset dataset = TDBFactory.createDataset(directory); Model model = dataset.getNamedModel("http://nameFile"); TDBLoader.loadModel(model, file ); 

现在,我想实现一个程序,检查图表是否在三重商店。

我写了这段代码:

 String queryStr = "select * {graph  { ?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”中的exceptionjava.lang.UnsupportedOperationException:Quad:subject不能为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)
在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)
at 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文件没有这些三元组! 为什么要加载这些三元组?

我想数据加载的代码是在与查询代码不同的程序中运行的。 如果是的话,那么

 TDB.sync(dataset) 

(使用事务会更好,或使用命令行工具进行批量加载)。