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 Mon, 14 Aug 2023 16:08:44 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
Fri, 22 Jul 2022 10:10:16 GMT
Semicolon in SPARQL

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.


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

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