0

I have a question for you:

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:

Exception in thread "main" java.lang.UnsupportedOperationException: Quad: subject cannot be null

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)

I get this error on this line:

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: null

but, my RDF file don't have these triples! Why these triples are loaded?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Musich87
  • 562
  • 1
  • 12
  • 31
  • Where do you initialize *results*? – Alessandro Suglia Sep 16 '14 at 09:49
  • Sorry, I forgot to copy a part. I have edited my post – Musich87 Sep 16 '14 at 09:53
  • The problem is when I read the model ( Model model = dataset.getNamedModel("http://nameFile");). Can you help me? – Musich87 Sep 16 '14 at 10:37
  • Which is the exact line that arise the error? Also you need to be sure that the loaded data are correct. – Alessandro Suglia Sep 16 '14 at 10:52
  • I get the error on this line: Statement statement = stmti.nextStatement(); – Musich87 Sep 16 '14 at 11:00
  • I have written the data on TripleStore using Model model = dataset.getNamedModel("http://nameFile"); TDBLoader.loadModel(model, label); When I do StmtIterator stmti = model.listStatements(); while (stmti.hasNext()) {Statement statement = stmti.nextStatement(); System.out.println(statement); }, I see all my data, but, if I launch Fuseki and I write this query: select * {graph { ?p ?o }}, I see only predicate while object is null. Why? – Musich87 Sep 16 '14 at 11:53
  • Note: syntactically, the `if/else` block prior to `StmtIterator stmti = model.listStatements();` is operating on some `model` instance that is now shown in the example itself. That is, the `model` defined in that `if/else` block is out of scope. The results of the `else` block has no effect. – Rob Hall Sep 16 '14 at 14:42

1 Answers1

2

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).

AndyS
  • 16,345
  • 17
  • 21
  • 1
    I have resolved this problem using TDB transactions: https://jena.apache.org/documentation/tdb/tdb_transactions.html – Musich87 Sep 18 '14 at 07:18