创建TDB存储并存储各种命名模型。
是否可以使用API列出TDB中包含的所有命名模型(因此您可以选择一个可以使用)或者是否需要事先知道要使用的模型的名称?
我在APi文档中没有发现任何关于此的信息(仅用于创建模型)或谷歌搜索。
答案 0 :(得分:3)
您可以使用sparql查询执行此操作:
[/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> |
----------------------------------
修改强>
抱歉,您刚刚意识到您已经明确要求列出API中的命名图表。所以,作为上述的替代方案:
String directory = "./tdb";
Dataset dataset = TDBFactory.createDataset(directory);
Iterator<String> graphNames = dataset.listNames();
while (graphNames.hasNext()) {
String graphName = graphNames.next();
....
}
答案 1 :(得分:1)
此SPARQL查询应该有效:
SELECT DISTINCT ?g WHERE { GRAPH ?g { } }