SPARQL

Thu, 07 Jul 2022 10:12:57 GMT

Properties
Name Value
Identifier sparql
Name SPARQL
Type Topic
Creation timestamp Thu, 07 Jul 2022 10:12:57 GMT
Modification timestamp Wed, 27 Jul 2022 06:29:53 GMT

Tags:  rdf

Examples

Data

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://www.learningsparql.com/ns/demo#i93234>
    foaf:nick "Dick" ;
    foaf:givenname "Richard" ;
    foaf:mbox "richard49@hotmail.com" ;
    foaf:surname "Mutt" ;
    foaf:workplaceHomepage <http://www.philamuseum.org/> ;
    foaf:aimChatID "bridesbachelor" .

Query

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?propertyLabel ?value
WHERE
{
    ?s ?property ?value .
    ?property rdfs:label ?propertyLabel .
}

Result

propertyLabel value
"personal mailbox" "richard49@hotmail.com"
"nickname" "Dick"
"Surname" "Mutt"
"Given name" "Richard"
"workplace homepage" http://www.philamuseum.org/
"AIM chat ID" "bridesbachelor"

The first triple pattern asks for all triples, because all three parts of the triple pattern are variables. The second triple pattern binds rdfs:label values associated with the ?property values from the first triple pattern to the ?propertyLabel variable. The SELECT list asks for these ?propertyLabel values, not the URIs that represent the properties, and the ?value values.

Query Forms

  • SELECT
  • CONSTRUCT
  • ASK
  • DESCRIBE

Back to top


Notes
Semicolon in SPARQL — Fri, 22 Jul 2022 10:10:16 GMT

A semicolon means the same thing in SPARQL that it means in Turtle: here comes another predicate and object to go with this triple’s subject.


Graph pattern — Mon, 25 Jul 2022 11:30:06 GMT

A set of triple patterns between curly braces in a SPARQL query is known as a graph pattern. Graph is the technical term for a set of RDF triples.


Back to top



Current context

Topic resources