[redland-dev] is librdf really posing SPARQL queries against Virtuoso?

lorena lorenae at fing.edu.uy
Tue Mar 20 22:07:29 EDT 2012


I've found here
http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSSQL2RDF
that, in order to directly pose queries against Virtuoso I should
state vsparql as query language, instead of sparql

"As indicated in the above diagram the Virtuoso Provider can be used
to execute RDF queries either directly against the Virtuoso graph
storage module supporting the SPARQL, SPARUL, SPARQL-BI query
languages or via the Rasqal query engine built into Redland which
supports the SPARQL query language. This is done by simply changing
the syntax of the query using the "vsparql" rather then default
"sparql" construct when executing a query as indicated in the sample
queries below: "

rdfproc -r xml -t "user='dba',password='dba',dsn='Demo'" gr query
sparql - "SELECT * WHERE { ?s ?p ?o }"            ;; via Redland
Rasqal engine

rdfproc -r xml -t "user='dba',password='dba',dsn='Demo'" gr query
vsparql - "SELECT * WHERE { ?s ?p ?o }"          ;; direct to Virtuoso
storage module

But If I do this I get no results at all!


This is a small working example of my code, based on Redland test.php

<?php

$world=librdf_php_get_world();

print "<p>Redland world opened\n</p>";

$options = "dsn='Local Virtuoso',user='dba',password='dba'";
$storage_name = "virtuoso";
$name = "http://example.org/salesInstancesSmall#";


# An existing store
$storage=librdf_new_storage($world, $storage_name, $name, $options);
if(!$storage) die("Failed to create new storage\n");

print "<p>Redland storage created</p>";

$model=librdf_new_model($world,$storage,'');
print "<p>Redland model created</p>";


$query = librdf_new_query($world, 'sparql', null, 'PREFIX
fn:<http://www.w3.org/2005/xpath-functions#> select
distinct(fn:substring-after ( "tatoo", "ta") as ?part) where { ?s ?p
?o}', null);

print "<p>Querying : </p>";
$results=librdf_model_query_execute($model, $query);
$count=1;
while($results && !librdf_query_results_finished($results)) {
  print "<p> result $count: {";
  for ($i=0; $i < librdf_query_results_get_bindings_count($results); $i++)
  {
    $val=librdf_query_results_get_binding_value($results, $i);
    if ($val){
      $nval=librdf_node_to_string($val);
    }
    else
      $nval='(unbound)';
    print "  ".librdf_query_results_get_binding_name($results, $i)."=".$nval;
  }
  print "}</p>";
  librdf_query_results_next($results);
  $count++;
}
if ($results) print "Returned $count results\n";
print "Done\n";
?>

And this is the output produced by the code above:

Redland world opened

Redland storage created

Redland model created

Querying :

result 1: { part="false"^^}
Returned 2 results Done

If I replace "sparql" with "vsparql" I get the following output:


Redland world opened

Redland storage created

Redland model created

Querying :
Done

Thanks
Lorena





On Tue, Mar 20, 2012 at 9:56 PM, lorena <lorenae at fing.edu.uy> wrote:
> As stated here http://librdf.org/docs/api/redland-storage-module-virtuoso.html
>
> "The Virtuoso Redland RDF Provider is an implementation of the Storage
> API, Model and Query interfaces of the Redland framework for RDF. This
> provider enables the execution of queries via the Redland Rasqal query
> engine or via Virtuoso query engine directly against the Virtuoso
> OpenSource Quad Store."
>
> So I just have to figure out how to skip Rasqal and execute the
> queries directly against Virtuoso.
>
> Any hints would be appreciated
>
> Lorena
>
> On Tue, Mar 20, 2012 at 9:40 PM, lorena <lorenae at fing.edu.uy> wrote:
>> Hi:
>>
>> I'm trying to use librdf to execute SPARQL queries over Virtuoso.
>> But, after getting errors trying to use some functions such as
>> fn:substring (having the fn prefix declared inside the query) I've
>> decided to take a look at Virtuoso's log (after enabling Virtuoso log
>> features using trace_on())
>>
>> To my surprise, although I successfully retrieve results, some of the
>> queries I perform are not logged at all, and other queries are similar
>> to the ones I intend to pose but are not the same.
>> Moreover, I've tested my queries using Virtuoso Conductor web client
>> and they run as expected.
>>
>> So, my questions are the following: is librdf doing some parsing or
>> re-writing on my queries? Is it somehow "loading" the model from
>> Virtuoso and using its own querying capabilities to execute my
>> queries? If so, how can I skip this step in order to force Virtuoso to
>> process the queries?
>>
>> thanks in advance
>> Lorena
>>
>> --
>> Lorena Etcheverry
>
>
>
> --
> Lorena Etcheverry



-- 
Lorena Etcheverry


More information about the redland-dev mailing list