next up previous contents
Next: Negation as failure Up: Body Previous: Non-existent relation   Contents

Optional part

A group of relations may be optional in a query : if target relations are found they are included in the answer otherwise the query does not fail.

Example : if there is a sister and a brother relation, return them, otherwise skip them.

?p  rdf:type  kmp:Person
?p  kmp:name ?n
option(
   ?p  kmp:sister  ?s
   ?p  kmp:brother ?b
)

The whole expression must be found for the option to return a result.

Option parts may be nested. A nested part is executed if the embedding part succeeds :

?p  rdf:type  kmp:Person
?p  kmp:name ?n1
option(
   ?p  kmp:sister  ?s
   option(?s kmp:name ?n2)
)

An optional part can also contain optional tests. The optional part succeeds if the tests succeed. In the example below, the optional part succeeds if there is a sister of age less that 45 :

?p  rdf:type  kmp:Person
?p  kmp:name ?n1
option(
   ?p  kmp:sister  ?s
   ?s kmp:age ?a
   ?a < 45
   option(?s kmp:name ?n2)
)



Olivier Corby 2005-07-01