<docbook><section><title>VirtRdfGraphDumpInfRule</title><bridgehead class="http://www.w3.org/1999/xhtml:h2">Virtuoso RDF Graph Dump based on Inference Rule Utility</bridgehead>
<para>The graph_dump procedure below can be used to export triples from Named RDF Graphs in N3 triple format to file, filtering based on the specified Inference rule and predicate/property URI:</para>
<para>Params:</para>
<itemizedlist mark="bullet" spacing="compact"><listitem>in <emphasis>srcgraph</emphasis> varchar - source graph </listitem>
<listitem>in <emphasis>format</emphasis> varchar - output format N3 is supported for now </listitem>
<listitem>in <emphasis>inf</emphasis> varchar - inference name </listitem>
<listitem>in <emphasis>pred</emphasis> varchar - predicate to filter </listitem>
<listitem>in <emphasis>out_file</emphasis> varchar - output file prefix </listitem>
<listitem>in <emphasis>file_length_limit</emphasis> := 1000000000 - maximum size of files data is dumped in</listitem>
</itemizedlist><programlisting>
create procedure graph_dump (in srcgraph varchar, in format varchar := &#39;N3&#39;, in inf varchar := null, in pred varchar := null,
			     in out_file varchar, in file_length_limit integer := 1000000000)
{
  declare qr, file_name varchar;
  declare env, ses, meta, data, h any;
  declare ses_len, max_ses_len, file_len, file_idx integer;
  set isolation = &#39;uncommitted&#39;;
  max_ses_len := 10000000;
  file_len := 0;
  file_idx := 1;
  if (format &lt;&gt; &#39;N3&#39;)
    signal (&#39;22023&#39;, &#39;The output format is not supported&#39;);
  file_name := sprintf (&#39;%s%06d.ttl&#39;, out_file, file_idx);
  string_to_file (file_name || &#39;.graph&#39;, srcgraph, -2);
  string_to_file (file_name, sprintf (&#39;# Dump of graph &lt;%s&gt;, as of %s\n&#39;, srcgraph, cast (now() as varchar)), -2);
  --env := vector (dict_new (16000), 0, &#39;&#39;, &#39;&#39;, &#39;&#39;, 0, 0);
  env := vector (dict_new (16000), 0, &#39;&#39;, &#39;&#39;, &#39;&#39;, 0, 0, 0, 0);
  ses := string_output ();
  if (inf is not null)
    inf := sprintf (&#39;define input:inference &quot;%s&quot;&#39;, inf);
  else  
    inf := &#39;&#39;;
  if (pred is not null)
    pred := sprintf (&#39;&lt;%s&gt;&#39;, pred);  
  else  
    pred := &#39;?p&#39;;
  qr := sprintf (&#39;select * from (sparql define input:storage &quot;&quot; %s select ?s %s as ?p ?o { graph &lt;%S&gt; { ?s %s ?o } } ) as sub option (loop)&#39;,
  		inf, pred, srcgraph, pred);
  exec (qr, null, null, vector (), 0, null, null, h);
  while (0 = exec_next (h, null, null, data))
    {
      declare &quot;s&quot;, &quot;p&quot;, &quot;o&quot; any;
      &quot;s&quot; := data[0];
      &quot;p&quot; := data[1];
      &quot;o&quot; := data[2];
      http_ttl_triple (env, &quot;s&quot;, &quot;p&quot;, &quot;o&quot;, ses);
      ses_len := length (ses);
      if (ses_len &gt; max_ses_len)
        {
          file_len := file_len + ses_len;
          if (file_len &gt; file_length_limit)
            {
              http (&#39; .\n&#39;, ses);
              string_to_file (file_name, ses, -1);
              file_len := 0;
              file_idx := file_idx + 1;
              file_name := sprintf (&#39;%s%06d.ttl&#39;, out_file, file_idx);
              string_to_file (file_name, sprintf (&#39;# Dump of graph &lt;%s&gt;, as of %s (part %d)\n&#39;, srcgraph, cast (now() as varchar), file_idx), -2);
              env := vector (dict_new (16000), 0, &#39;&#39;, &#39;&#39;, &#39;&#39;, 0, 0);
            }
          else
            string_to_file (file_name, ses, -1);
          ses := string_output ();
        }
    }
  exec_close (h);
  if (length (ses))
    {
      http (&#39; .\n&#39;, ses);
      string_to_file (file_name, ses, -1);
    }
}
;
</programlisting><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Example</bridgehead>
<para><ulink url="http://www.ontologyportal.org/">SUMO ontology</ulink> was recently mapped to DBpedia by its creators using RDF/XML and loaded into the <ulink url="http://dbpedia.org/sparql">DBpedia SPARQL Endpoint</ulink>.</para>
<emphasis>Issues</emphasis>:<itemizedlist mark="bullet" spacing="compact"><listitem>To add to DBpedia data sets, N3 is preferred format.
</listitem>
<listitem>Cross Links needed i.e.
 mapping &lt;#dbpediaURI&gt; owl:sameAs &lt;#SumoURI&gt; in addition to the authors links which are solely, &lt;#SumoURI&gt; owl:sameAs &lt;#DBpediaURI&gt;</listitem>
</itemizedlist><emphasis>Solution</emphasis>:<itemizedlist mark="bullet" spacing="compact"><listitem>Make an inference rules graph where owl:sameAs is explicitly asserted to be an owl:SymmetricalProperty type.
<programlisting>ttlp(&#39;owl:sameAs a owl:SymmetricalProperty .&#39;, &#39;&#39;, &#39;rule_graph&#39;);
</programlisting></listitem>
<listitem>Make a Named Rule that&#39;s associated the the Named Graph in step above.
<programlisting>rdfs_rule_set (&#39;sas&#39;, &#39;rule_graph&#39;);
</programlisting></listitem>
<listitem>Run the graph_dump export procedure with the inference rule parameter and predicate/property filter option to export the data to file, in N3 format and with necessary <span style="color: red">
      UNKNOWN tag:
      http://www.w3.org/1999/xhtml:nowikiowl:sameas cross links.
graph_dump (&#39;http://www.ontologyportal.org/SUMO#&#39;, &#39;N3&#39;, &#39;sas&#39;, &#39;http://www.w3.org/2002/07/owl#sameAs&#39;, &#39;sumo_&#39;);
</span></listitem>
</itemizedlist></section></docbook>