SPARQL Example 3 – distinct, union, optional

DISTINCT 사용

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?name
WHERE {
?book a bibo:Book ;
rdfs:label ?label ;
dcterms:creator ?person .
?person foaf:name ?name .
}

 

UNION 사용

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
WHERE {
{ ?id foaf:name “고은”@ko . }
UNION 
{ ?id test:birthYear ?birth .
FILTER (?birth=1990) }
}

 

OPTIONAL 사용

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
WHERE {
?id foaf:name ?name ;
test:birthYear ?birth .
FILTER(?birth>1960)
OPTIONAL { ?id test:deathYear ?death . }
}

 

more …