Graph Construction

SPARQL Construction of RDF Graphs - CONSTRUCT itself defines a Template for the Construction of RDF Graphs.

For example given a simple Knowledge Base with a Prefix to a Namespace and two Persons that are connected to some Blank Node with a Name and id for each Person.

This Namespace can be transformed into the foaf Namespace where one has also something like names, but one has to substitute the username with the a foaf name to have a foaf output. In the Graph Pattern one is looking for all users that have the userid or username from the Knoweldge Base and one can construct/define a new pattern where one puts the Subject from the original Pattern and Name and one substitutes the Property to the Property of the new Namespace, namely from the foaf namespace.

In the end the result of the Query will be if it was defined as serialized RDF/XML will be an XML file based on RDF with the Content of the Database in connection with for instance the foaf Namespace which was in the predefined Template of the construct Statement. This is a simple way to translate from one Vocabulary to another Vocabulary. Therefore, it is for Vocabulary transcription/transformation which is very handy.

  • CONSTRUCT defines a template for the construction of new RDF Graphs.

Data:

     @prefix org: <http://example.com/ns#>] .

     _:a org:username "Hevok" .
     _:a org:userid 5 .

     _:b org:username "EVA" .
     _:b org:userid 2 .

Query:

     PREFIX foaf: <http://xmlns.com/foaf/0.1/>]
     PREFIX org: <http://example.com/ns#>]

     CONSTRUCT { ?x foaf:name ?name }
     WHERE { ?x org:name ?name }
  • Result of a CONSTRUCT Query as serialized RDF/XML
    <rdf:RDF
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-nx#"
          xmlns:foaf="http://xmlns.com/foaf/0.1/">]
          <rdf:Description>
              <foaf:name>Hevok</foaf:name>
          </rdf:Description>
          <rdf:Description>
              <foaf:name>EVA</foaf:name>
          </rdf:Description>
    </rdf:RDF>
    
graph-construction.png/
Edit tutorial

Comment on This Data Unit