Search code examples
sparqldbpediasparqlwrapper

SPARQL - What does a single colon do in a prefix?


I've often seen a SPARQL query starting with this prefix:

PREFIX : <http://dbpedia.org/resource/>

But what exactly does it mean to use only a colon ":" in a prefix? I usually know it as putting another abbreviation in front of it. Like for example here:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

Is there a reason to write it this way, and if so, what is the function of the prefix? I would imagine that this would cover any other abbreviations that were not assigned. But unfortunately I've not found anything specific about this on the Internet


Solution

  • There’s no special functionality involved. It’s a regular prefix label, which happens to be empty.

    SPARQL: Prefixed Names (bold emphasis mine):

    The PREFIX keyword associates a prefix label with an IRI. A prefixed name is a prefix label and a local part, separated by a colon ":". A prefixed name is mapped to an IRI by concatenating the IRI associated with the prefix and the local part. The prefix label or the local part may be empty.

    So these three snippets are equivalent:

    SELECT * WHERE {
      ?person a <http://xmlns.com/foaf/0.1/Person> .
    }
    
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    SELECT * WHERE {
      ?person a foaf:Person .
    }
    
    PREFIX : <http://xmlns.com/foaf/0.1/>
    SELECT * WHERE {
      ?person a :Person .
    }
    

    Using an empty prefix label in SPARQL queries might make sense if all, or almost all, IRIs come from the same ontology, because the query might become more readable then.