dawg-query-001

Optional triples: single optional triple case.

Data

file:dawg-data-01.n3

Query

# Get name, and optionally the mbox, of each person

SELECT ?name ?mbox
WHERE
    (?person foaf:name ?name)
OPTIONAL
    (?person foaf:mbox	?mbox)
USING foaf FOR 

Results

dawg-tests/dawg-result-001.n3

namembox
"Alice"<mailto:alice@work>
"Eve"NULL
"Bob"<mailto:bob@work>
"Bob"<mailto:bob@home>

dawg-query-002

Optional triples: multiple triples in one optional clause. Must find a name for each person known.

Data

file:dawg-data-01.n3

Query

# Get names of people, together with the names of people they know.

SELECT ?name, ?name2
WHERE
    (?person foaf:name ?name)
OPTIONAL
    (?person foaf:knowns ?p2)
    (?p2     foaf:name   ?name2)
USING foaf FOR 

Results

dawg-tests/dawg-result-002.n3

namename2
"Bob""Alice"
"Alice""Bob"
"Eve"NULL

dawg-query-003

Optional triples: multiple optional clauses.

Data

file:dawg-data-01.n3

Query

# Get names and mboxes, each of which may be optional.

SELECT ?name, ?mbox
WHERE
    (?person rdf:type foaf:Person)
OPTIONAL
    (?person foaf:name  ?name)
OPTIONAL
    (?person foaf:mbox  ?mbox)
USING foaf FOR 

Results

dawg-tests/dawg-result-003.n3

namembox
"Alice"<mailto:alice@work>
"Bob"<mailto:bob@work>
"Bob"<mailto:bob@home>
NULL<test:fred@edu>
"Eve"NULL