<docbook><section><title>VirtTipsAndTricksGuideConstructINSERTStatement</title><title>How can I use INSERT via CONSTRUCT Statements?</title>How can I use INSERT via CONSTRUCT Statements?
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">What?</bridgehead>
<para>Use of SPARUL to add triples to a Named Graph.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">Why?</bridgehead>
<para>Imagine a situation where you seek to create mappings between datasets across Linked Data Spaces.
 For example, we have two datasets across the schema.org and schema.rdfs.org data spaces and we seek to mint owl:equivalentClass and owl:equivalentProperty relations across the aforementioned data spaces in a third dataspace hosted by a Virtuoso instance.</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">How?</bridgehead>
<para>You can write an ordinary CONSTRUCT statement, ensure that it generates the triples intended to be added, and then replace the leading CONSTRUCT keyword with the INSERT INTO <span style="color: red">
      UNKNOWN tag:
      http://www.w3.org/1999/xhtml:destination-graph phrase.</span></para>
<para>The example below shows how CONSTRUCT is used to manufacture the triples required by the Virtuoso hosted dataset.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Example</bridgehead>
<orderedlist spacing="compact"><listitem>Assume the following CONSTRUCT statement: <programlisting>CONSTRUCT 
  {  
    ?s &lt;http://www.w3.org/2002/07/owl#equivalentClass&gt; `iri (bif:replace(?o,&#39;http://schema.rdfs.org/&#39;, &#39;http://schema.org/&#39;))`
   } 
FROM &lt;http://www.openlinksw.com/schemas/rdfs&gt; 
WHERE 
  { 
    ?s &lt;http://www.w3.org/2002/07/owl#equivalentClass&gt; ?o
  };
</programlisting></listitem>
<listitem>Execute the CONSTRUCT query from the htp://cname/sparql SPARQL endpoint.
</listitem>
<listitem>View the generated triples to ensure they are correct.
</listitem>
<listitem>Replace CONSTRUCT with INSERT INTO: <programlisting>SPARQL INSERT INTO &lt;http://www.openlinksw.com/schemas/rdfs&gt;  
  {  
    ?s &lt;http://www.w3.org/2002/07/owl#equivalentClass&gt; `iri (bif:replace(?o,&#39;http://schema.rdfs.org/&#39;, &#39;http://schema.org/&#39;))`
   } 
FROM &lt;http://www.openlinksw.com/schemas/rdfs&gt; 
WHERE 
  { 
    ?s &lt;http://www.w3.org/2002/07/owl#equivalentClass&gt; ?o
  } ;
</programlisting></listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h3">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink>.
</listitem>
<listitem><ulink url="http://docs.openlinksw.com/virtuoso/rdfandsparql.html">RDF Data Access and Data Management</ulink>.
</listitem>
<listitem><ulink url="VirtTipsAndTricksGuideConstructPreparedStatement">Usage of CONSTRUCT with Prepared Statements</ulink>.
</listitem>
</itemizedlist></section></docbook>