Hi Claus,

As described in http://docs.openlinksw.com/virtuoso/fn_exec.html, the "rows" 
parameter is  "An output array with one element per result row containing an 
array with the leftmost column as element 0 and so forth". 

Processing further the result can be done for ex. such as:
exec (,,,,, data);
for (declare i,l int, i := 0, l := length (data); i < l; i := i + 1)
   {
     -- do sth with for ex. with data[i][0],[i][1] etc.
   }


Additionally, the example function "param_passing_demo" in 
http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsparqlinline 
uses exec with SPARQL query.

Hope this helps.

Best Regards,
Rumi

----- Original Message ----- 
  From: CStadler 
  To: virtuoso-users@lists.sourceforge.net 
  Sent: Tuesday, March 01, 2011 8:40 PM
  Subject: [Virtuoso-users] Dump arbitrary query result as N-Triples


  Hi,

  So far I have used the script at the end of this mail for dumping a graph as 
n-triples (basically its an adaption from 
http://docs.openlinksw.com/virtuoso/rdfperformancetuning.html).

  However now I want to adapt it so I can pass a string with graph-patterns in 
order to be able to specify filters on what should be dumped.
  The dump script I use contains the line:

  for (select * from (sparql define input:storage "" select ?s ?p ?o { graph 
`iri(?:srcgraph)` { ?s ?p ?o } } ) as sub option (loop)) do

  I want to change it so it works with a dynamically created query, something 
like:
  str := sprintf ('sparql define input:storage "" select ?s ?p ?o { %s }', 
myPattern)
  myPattern could be something like "?s ?p ?o . ?s a Type . Filter(...)")

  And this is where I am stuck now:
  I can do exec(...) but then I don't know how I can iterate the result in the 
for loop.

  The doc at
  http://docs.openlinksw.com/virtuoso/fn_exec.html
  doens't give an example how to further process the result.



  Alternatively, I thought I could use isql and do something like:

   ./isql 1111 dba dba "EXEC=Set Blobs On; Sparql define output:format 'NT' 
Construct {?s ?p ?o .} From <http://mygraph.org> {?s ?p ?o .};"

  However, first this ouputs additional lines for human readability and 
therefore doesn't directly produce a valid rdf file (although it is possible to 
cut the invalid heading and trailing lines away with head/tail, it is not a 
very clean solution)

  And second 'NT' is not a valid format (the docs don't mention it):

  from http://docs.openlinksw.com/virtuoso/rdfsparql.html
      "Supported values for output:format are RDF/XML and TURTLE  (or TTL). If 
both output:valmode and output:format are specified, output:format has higher 
priority, raising an error if output:valmode is set to a value other than LONG. 
"


  Best regards,
  Claus Stadler



  For the sake of completeness here is the dump script I want to further adapt:

  drop procedure dump_graph_nt;
  create procedure dump_graph_nt(in srcgraph varchar, in out_file varchar, in 
file_length_limit integer := -1)
  {
    declare file_name varchar;
    declare env, ses 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;
    file_name := sprintf ('%s-%06d.nt', out_file, file_idx);
    string_to_file (file_name || '.graph', srcgraph, -2);
    env := vector (0, 0, 0);
    ses := string_output ();
    for (select * from (sparql define input:storage "" select ?s ?p ?o { graph 
`iri(?:srcgraph)` { ?s ?p ?o } } ) as sub option (loop)) do
      {
        http_nt_triple (env, "s", "p", "o", ses);
        ses_len := length (ses);
        if (ses_len > max_ses_len)
          {
            file_len := file_len + ses_len;
            if (file_length_limit >= 0 and file_len > file_length_limit)
              {
                string_to_file (file_name, ses, -1);
                file_len := 0;
                file_idx := file_idx + 1;
                file_name := sprintf ('%s-%06d.nt', out_file, file_idx);
                env := vector (0, 0, 0);
              }
            else
              string_to_file (file_name, ses, -1);
            ses := string_output ();
          }
      }
    if (length (ses))
      {
        string_to_file (file_name, ses, -1);
      }
  };




------------------------------------------------------------------------------


  ------------------------------------------------------------------------------
  Free Software Download: Index, Search & Analyze Logs and other IT data in 
  Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
  generated by your applications, servers and devices whether physical, virtual
  or in the cloud. Deliver compliance at lower cost and gain new business 
  insights. http://p.sf.net/sfu/splunk-dev2dev


------------------------------------------------------------------------------


  _______________________________________________
  Virtuoso-users mailing list
  Virtuoso-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to