开发者

Is there a way to list the models contained in a TDB storage?

A TDB storage is created and various named models stored within.

Is it posible with the API to list all the named models contained in the TDB (so you can pick one to work with) or is it necesar开发者_开发百科y to know the name of the model you want to work with beforehand?

I find nothing in the APi documentation about this (just for creating models) or googling.


You can do it with a sparql query:

[/tmp]
ian@rowan-15 $ cat > test.nq
<http://example.org/a> <http://example.org/p> "in graph one" <http://example.org/graph/one> .
<http://example.org/a> <http://example.org/p> "in graph two" <http://example.org/graph/two> .
[/tmp]
ian@rowan-15 $ mkdir tdb
[/tmp]
ian@rowan-15 $ tdbloader --loc=tdb test.nq
-- Start triples data phase
** Load empty triples table
-- Start quads data phase
** Load empty quads table
Load: test.nq -- 2011/05/27 08:55:59 BST
-- Finish triples data phase
-- Finish quads data phase
2 quads loaded in 0.05 seconds [Rate: 37.74 per second]
-- Start quads index phase
** Index GSPO->GPOS: 2 slots indexed
** Index GSPO->GOSP: 2 slots indexed in 0.00 seconds [Rate: 2,000.00 per second]
** Index GSPO->POSG: 2 slots indexed
** Index GSPO->OSPG: 2 slots indexed
** Index GSPO->SPOG: 2 slots indexed
-- Finish quads index phase
** 2 quads indexed in 0.01 seconds [Rate: 153.85 per second]
-- Finish triples load
-- Finish quads load
** Completed: 2 quads loaded in 0.09 seconds [Rate: 23.26 per second]
[/tmp]
ian@rowan-15 $ tdbquery --loc=tdb "select ?g where {graph ?g {?s ?p ?o}}"
----------------------------------
| g                              |
==================================
| <http://example.org/graph/one> |
| <http://example.org/graph/two> |
----------------------------------

Edit

Sorry, just realised that you specifically asked for listing the named graphs from the API. So, as an alternative to the above:

String directory = "./tdb";
Dataset dataset = TDBFactory.createDataset(directory);
Iterator<String> graphNames = dataset.listNames();
while (graphNames.hasNext()) {
    String graphName = graphNames.next();
    ....
}


This SPARQL query should work:

SELECT DISTINCT ?g WHERE { GRAPH ?g { } }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜