Warning:
This wiki has been archived and is now read-only.

Decision Incubator Tools/SPARQL CONSTRUCT

From Decision XG
Jump to: navigation, search

SPARQL CONSTRUCT (and DESCRIBE)

A CONSTRUCT query creates new triples, as opposed to just binding variables and "selecting" existing triples as the SELECT query does. Hence, while the result of a SELECT query is a set of variable bindings (i.e. data from existing triples) the result of a CONSTRUCT query is an RDF graph.

The SPARQL specification has this example to illustrate a basic CONSTRUCT query:

Given the following data:

  @prefix  foaf:  <http://xmlns.com/foaf/0.1/> .
  _:a    foaf:name   "Alice" .
  _:a    foaf:mbox   <mailto:alice@example.org> .

We can vrite the following SPARQL query:

  PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
  PREFIX vcard:   <http://www.w3.org/2001/vcard-rdf/3.0#>
  CONSTRUCT   { <http://example.org/person#Alice> vcard:FN ?name }
  WHERE       { ?x foaf:name ?name }

That query constructs a new RDF graph containing one new triple with vcard information about Alice:

  @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .
  <http://example.org/person#Alice> vcard:FN "Alice" .

In this way one can for instance create additional triples to insert into an ontology based on SPARQL queries. SPARQL does not automatically do anything more with the RDF graph output, but it can then be treated programmatically and used as a new ontology, included as triples in an existing one or something else.


SPARQL DESCRIBE is another thing that outputs an RDF graph, however, I find the idea of what it actually does a bit vague. Basically, DESCRIBE should return an RDF graph that describes, i.e. "is about", whatever resource or graph pattern is given as the selection criteria. It is however up to the provider of the RDF data and the implementation of the SPARQL engine to determine exactly what "is about" means. (Comment (Eva): I never experimented with this so I don't really know how it works in practice. I didn't see this in use in any of our applications so far, while we are frequently using the CONSTRUCT.)