Hello Claus,

sparql define output:format "NT" construct { ?s a ?t } from virtrdf:
where { ?s a ?t };

works, the doc is slightly out-of-date there.

For iteration over result-set of an arbitrary query, use exec_next()
http://docs.openlinksw.com/virtuoso/fn_exec_next.html
in a loop that begins with exec() with cursor output variable as an
argument and ends with exec_close() after it is out of data.

Best Regards,

Ivan Mikhailov
OpenLink Software
http://virtuoso.openlinksw.com


On Tue, 2011-03-01 at 20:40 +0100, CStadler wrote:
> 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