2009-08-04 230 views
0

我具有以下示例三倍過濾SPARQL結果

r1 -> property -> resourceA 
r1 -> property -> resourceB 
r1 -> property -> resourceC 
resourceA -> name -> word1 
resourceB -> name -> word2 
resourceC -> name -> word4 

r2 -> property -> resourceD 
r2 -> property -> resourceE 
r2 -> property -> resourceF 
resourceD -> name -> word1 
resourceE -> name -> word2 
resourceF -> name -> word3 

r3 -> property -> resourceG 
r3 -> property -> resourceH 
r3 -> property -> resourceI 
resourceG -> name -> word5 
resourceH -> name -> word6 
resourceI -> name -> word7 

作爲參數i使用WORD1和WORD2。我想要得到所有的單詞。 word1和word2,它們與word1和word2一起出現。

從這個例子的結果必然是:

word1 
word2 
word3 
word4 

我也實在沒有想法,如何使這個:(

回答

2

假設謂詞name是所有word S也是一樣的,也沒有其他三元與name斷言:

SELECT DISTINCT ?w { 
    ?s <name> ?w 
} 
ORDER BY ?w 

問題後編輯被編輯:

SELECT DISTINCT ?w { # select each word only once 

    # match three properties under the same resource 
    ?r <property> ?p1, ?p2, ?p3. 

    # two of the properties must have names "word1" and "word2" 
    ?p1 <name> "word1" . 
    ?p2 <name> "word2" . 

    # third property name may be anything, including "word1" and "word2" 
    ?p3 <name> ?w . 
} 
ORDER BY ?w # return words in sorted order 
+0

它的作品!大!非常感謝你! :) – cupakob 2009-08-04 13:52:48