views:

64

answers:

1

I have following example triples

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

As parameter i use word1 and word2. I want to get all words incl. word1 and word2, which occurrence with the word1 and word2 together.

The result from this example must be:

word1
word2
word3
word4

I have really no idea, how to make this :(

+2  A: 

Assuming the predicate name is the same for all words and there are no other triples with the name predicate:

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


Edited after the question was edited:

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
laalto
it works! great! thank you very much! :)
cupakob