Jena TDB to store and query using API

前端 未结 2 1735
灰色年华
灰色年华 2021-02-09 18:28

I am new to both Jena-TDB and SPARQL, so it might be a silly question. I am using tdb-0.9.0, on Windows XP.

I am creating the TDB model for my trail_1.rdf f

相关标签:
2条回答
  • 2021-02-09 19:12

    The problem in your part 1 code is, I think, you are not committing the data .

    Try with this version of your part 1 code:

       String directory = "D:\\Project\\Store_DB\\data1\\tdb";
       Dataset dataset = TDBFactory.createDataset(directory);
    
       Model tdb = dataset.getDefaultModel();
    
       // read the input file
       String source = "D:\\Project\\Store_DB\\tmp\\trail_1.rdf";
       FileManager.get().readModel( tdb, source);
    
       dataset.commit();//INCLUDE THIS STAMEMENT
    
       tdb.close();
       dataset.close();
    

    and then try with your part 3 code :) ....

    0 讨论(0)
  • 2021-02-09 19:17

    For part (i) of your question, yes, your understanding is correct.

    For part (ii), the reason that listNames does not return any results is because you have not put your data into a named graph. In particular,

    Model tdb = dataset.getDefaultModel();
    

    means that you are storing data into TDB's default graph, i.e. the graph with no name. If you wish listNames to return something, change that line to:

    Model tdb = dataset.getNamedGraph( "graph42" );
    

    or something similar. You will, of course, then need to refer to that graph by name when you query the data.

    If your goal is simply to test whether or not you have successfully loaded data into the store, try the command line tools bin/tdbdump (Linux) or bat\tdbdump.bat (Windows).

    For part (iii), I tried your code on my system, pointing at one of my TDB images, and it works just as one would expect. So: either the TDB image you're using doesn't have any data in it (test with tdbdump), or the code you actually ran was different to the sample above.

    0 讨论(0)
提交回复
热议问题