2011-05-26 20 views
2

一個TDB存儲和存儲內的各種型號命名。有沒有辦法列出TDB存儲中包含的模型?創建

使用API​​可以列出TDB中包含的所有命名模型(這樣您可以選擇一個模型來處理),還是需要事先知道要使用的模型的名稱?

我覺得這個沒什麼的API文檔中(只用於創建模型)或谷歌搜索。

回答

3

您可以用SPARQL查詢做到這一點:

[/tmp] 
[email protected] $ 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] 
[email protected] $ mkdir tdb 
[/tmp] 
[email protected] $ 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] 
[email protected] $ 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

此SPARQL查詢應該工作:

SELECT DISTINCT ?g WHERE { GRAPH ?g { } } 
相關問題