SPARQL Example 1

SELECT Query 1

SELECT ?id
WHERE {
?id rdf:type <http://test.com/ontology/Author> .
}

SELECT Query 2

SELECT ?id ?name
WHERE {
?id rdf:type < http://test.com/ontology/Author> .
?id < http://xmlns.com/foaf/0.1/name> ?name .
}

SELECT Query 3

SELECT ?id ?name
WHERE {
?id rdf:type <http://test.com/ontology/Author> ;
<http://xmlns.com/foaf/0.1/name> ?name .
}

PREFIX 사용

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?name
WHERE {
?id rdf:type test:Author ;
foaf:name ?name .
}

 

FILTER 사용

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?name
WHERE {
?id rdf:type test:Author ;
foaf:name ?name ;
test:birthYear ?birth .
FILTER(?birth=1933)
}

 

ORDER BY 사용 1

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?name
WHERE {
?id rdf:type test:Author ;
foaf:name ?name ;
test:birthYear ?birth .
FILTER(?birth=1933)
}
ORDER BY ?id

 

ORDER BY 사용 2

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?name
WHERE {
?id rdf:type test:Author ;
foaf:name ?name ;
test:birthYear ?birth .
FILTER(?birth=1933)
}
ORDER BY DESC (?id)

 

ORDER BY 사용 3

PREFIX test: <http://test.com/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?name
WHERE {
?id rdf:type test:Author ;
foaf:name ?name ;
test:birthYear ?birth .
FILTER(?birth=1933)
}
ORDER BY ?name DESC (?id)

 

more …