2016-06-20 128 views
5

我有非託管三元組作爲存儲在我的內容數據庫中的單個文檔的一部分存儲。基本上每個文檔都代表一個人,而定義的三元組指定該人員的經理的文檔URI。我正在嘗試使用SPARQL來確定經理與層次結構中所有下層人員之間的路徑長度。有什麼方法可以優化SPARQL查詢嗎?

文檔中的三元看起來像

<sem:triple xmlns:sem="http://marklogic.com/semantics"> 
    <sem:subject>http://rdf.abbvienet.com/infrastructure/person/10740024</sem:subject> 
    <sem:predicate>http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager</sem:predicate> 
    <sem:object>http://rdf.abbvienet.com/infrastructure/person/10206242</sem:object> 
</sem:triple> 

我發現在層次以下SPARQL查詢,可用於返回一個經理,aperson低於他們,節點數量遙遠他們是。

select ?manager ?leaf (count(?mid) as ?distance) { 
    BIND(<http://rdf.abbvienet.com/infrastructure/person/10025613> as ?manager) 
    ?leaf <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>* ?mid . 
    ?mid <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>+ ?manager . 
} 
group by ?manager ?leaf 
order by ?manager ?leaf 

這工作,但速度很慢,即使在層次樹,我看到的是一個或兩個級別深度的情況下,各地15S。我在數據庫中有63,139這種類型的管理三元組。

+0

不應該是'ORDER BY?leaf',因爲您只有'?manager'的一個綁定。 – scotthenninger

回答

6

我認爲最大的問題將是BIND() - MarkLogic 8並未優化您使用的模式。你可以嘗試用你的常數代入你使用?manager變量的地方,看看這是否有很大的不同?即:

select ?leaf (count(?mid) as ?distance) { 
    ?leaf <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>* ?mid . 
    ?mid <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>+ 
    <http://rdf.abbvienet.com/infrastructure/person/10025613> . 
} 
group by ?leaf 
order by ?leaf 

的StackOverflow是不是一個偉大的地方來回答性能類似這樣的問題,因爲它確實需要我們共同努力來幫助你交談。也許你可以嘗試聯繫supportMarkLogic developer mailing list這類問題?

+0

如果沒有綁定,它的執行速度非常快。謝謝。 –

+0

只是另一種評論。如果我在'sem:sparql'調用中設置綁定參數,它也很快。當我直接在SPARQL中綁定時,速度很慢。 –