VOS.VirtRdfGraphDumpInfRule

  • Topic
  • Discussion
  • VOS.VirtRdfGraphDumpInfRule(Last) -- DAVWikiAdmin? , 2017-06-13 05:41:56 Edit WebDAV System Administrator 2017-06-13 01:41:56

    Virtuoso RDF Graph Dump based on Inference Rule Utility

    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:

    Params:

    • in srcgraph varchar - source graph
    • in format varchar - output format N3 is supported for now
    • in inf varchar - inference name
    • in pred varchar - predicate to filter
    • in out_file varchar - output file prefix
    • in file_length_limit := 1000000000 - maximum size of files data is dumped in

    create procedure graph_dump (in srcgraph varchar, in format varchar := 'N3', 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 = 'uncommitted';
      max_ses_len := 10000000;
      file_len := 0;
      file_idx := 1;
      if (format <> 'N3')
        signal ('22023', 'The output format is not supported');
      file_name := sprintf ('%s%06d.ttl', out_file, file_idx);
      string_to_file (file_name || '.graph', srcgraph, -2);
      string_to_file (file_name, sprintf ('# Dump of graph <%s>, as of %s\n', srcgraph, cast (now() as varchar)), -2);
      --env := vector (dict_new (16000), 0, '', '', '', 0, 0);
      env := vector (dict_new (16000), 0, '', '', '', 0, 0, 0, 0);
      ses := string_output ();
      if (inf is not null)
        inf := sprintf ('define input:inference "%s"', inf);
      else  
        inf := '';
      if (pred is not null)
        pred := sprintf ('<%s>', pred);  
      else  
        pred := '?p';
      qr := sprintf ('select * from (sparql define input:storage "" %s select ?s %s as ?p ?o { graph <%S> { ?s %s ?o } } ) as sub option (loop)',
      		inf, pred, srcgraph, pred);
      exec (qr, null, null, vector (), 0, null, null, h);
      while (0 = exec_next (h, null, null, data))
        {
          declare "s", "p", "o" any;
          "s" := data[0];
          "p" := data[1];
          "o" := data[2];
          http_ttl_triple (env, "s", "p", "o", ses);
          ses_len := length (ses);
          if (ses_len > max_ses_len)
            {
              file_len := file_len + ses_len;
              if (file_len > file_length_limit)
                {
                  http (' .\n', ses);
                  string_to_file (file_name, ses, -1);
                  file_len := 0;
                  file_idx := file_idx + 1;
                  file_name := sprintf ('%s%06d.ttl', out_file, file_idx);
                  string_to_file (file_name, sprintf ('# Dump of graph <%s>, as of %s (part %d)\n', srcgraph, cast (now() as varchar), file_idx), -2);
                  env := vector (dict_new (16000), 0, '', '', '', 0, 0);
                }
              else
                string_to_file (file_name, ses, -1);
              ses := string_output ();
            }
        }
      exec_close (h);
      if (length (ses))
        {
          http (' .\n', ses);
          string_to_file (file_name, ses, -1);
        }
    }
    ;
    

    Example

    SUMO ontology was recently mapped to DBpedia by its creators using RDF/XML and loaded into the DBpedia SPARQL Endpoint.

    Issues:
    • To add to DBpedia data sets, N3 is preferred format.
    • Cross Links needed i.e. mapping <#dbpediaURI> owl:sameAs <#SumoURI> in addition to the authors links which are solely, <#SumoURI> owl:sameAs <#DBpediaURI>
    Solution:
    • Make an inference rules graph where owl:sameAs is explicitly asserted to be an owl:SymmetricalProperty type.

      ttlp('owl:sameAs a owl:SymmetricalProperty .', '', 'rule_graph');

    • Make a Named Rule that's associated the the Named Graph in step above.

      rdfs_rule_set ('sas', 'rule_graph');

    • 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 owl:sameas cross links.

      graph_dump ('http://www.ontologyportal.org/SUMO#', 'N3', 'sas', 'http://www.w3.org/2002/07/owl#sameAs', 'sumo_');