Jena TDB to store and query using API

巧了我就是萌 提交于 2019-12-03 09:06:15

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.

user3359752

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!