tripod icon indicating copy to clipboard operation
tripod copied to clipboard

Support to Virtuoso Openlink Sparql Endpoint

Open samuraraujo opened this issue 11 years ago • 6 comments

Do you api support any sparql endpoint?

I try to run a command like Book.all.resources and I got this error:

Tripod::Errors::BadSparqlRequest (Virtuoso 37000 Error SP030: SPARQL compiler, line 1: syntax error at 'SELECT' befor e 'DISTINCT'

SPARQL query: define sql:big-data-const 0 DESCRIBE ?uri WHERE { SELECT DISTINCT ?uri (http://dbpedia.org as ?graph) WHERE { GRAPH http://dbpedia.org { ?uri a http://dbpedia.org/ontology/Book . ?uri ?p ?o } } }): app/controllers/search_controller.rb:4:in `index'

This error was cause because the syntax of the describe query is incorrect.

Did you implement the queries according to the sparql specification?

The project is really great and I hope it takes off. Best, Samur

samuraraujo avatar Oct 01 '13 14:10 samuraraujo

Hi Samur

This query works for me on the dbpedia endpoint:

DESCRIBE ?uri WHERE { SELECT DISTINCT ?uri (http://dbpedia.org as ?graph) WHERE { GRAPH http://dbpedia.org { ?uri a http://dbpedia.org/ontology/Book . ?uri ?p ?o } } LIMIT 5}

(Please note that I added a LIMIT clause in my test, to avoid retrieving too much data).

The problem with your query seems to be that there are no '<' and '>' around the URIs.

I must admit I don't know what 'define sql:big-data-const 0' means as I'm not really familiar with Virtuoso's extra features.

Is that a query that was generated automatically by Tripod? If that is the case can you paste the code you used to create your 'Book' object in Tripod. Perhaps there is something wrong there that we might be able to help with.

In general, Tripod is based on SPARQL 1.1 and should work with any endpoint that supports that.

BillSwirrl avatar Oct 02 '13 12:10 BillSwirrl

Ah, it seems that the Github comments box strips some formatting - sorry!

This is my working query, hopefully now showing correctly

DESCRIBE ?uri WHERE { SELECT DISTINCT ?uri (<http://dbpedia.org> as ?graph) WHERE { GRAPH <http://dbpedia.org> { ?uri a <http://dbpedia.org> . ?uri ?p ?o } } LIMIT 5 }

So I imagine your original query did in fact have the angle brackets. So I'm not sure what the problem is, other than perhaps something to do with that initial define statement.

BillSwirrl avatar Oct 02 '13 12:10 BillSwirrl

Shoot, I made a duplicate (see #24)! Long story short, patch is here.

fonji avatar Nov 06 '13 14:11 fonji

I'm having the same problem with Virtuoso, I think.

I have the following model

Tripod.configure do |config|
  config.query_endpoint = 'http://www.leipzig-data.de:8890/sparql'
  config.timeout_seconds = 30
end

class Street

  include Tripod::Resource

  rdf_type "http://leipzig-data.de/Data/Model/Strasse"
  graph_uri "http://leipzig-data.de/Data/Strassenverzeichnis/"

  field :label, RDF::RDFS.label
end

And when I try 'Street.first' in a console I get this error back:

[1] pry(main)> Street.first
Tripod::Errors::BadSparqlRequest: Virtuoso 37000 Error SP030: SPARQL compiler, line 1: syntax error at 'SELECT' before 'DISTINCT'

SPARQL query:
define sql:big-data-const 0 SELECT * { SELECT DISTINCT ?uri (<http://leipzig-data.de/Data/Strassenverzeichnis/> as ?graph) WHERE { GRAPH <http://leipzig-data.de/Data/Strassenverzeichnis/> { ?uri a <http://leipzig-data.de/Data/Model/Strasse> . ?uri ?p ?o } } } LIMIT 1
from /Users/lars/.rvm/gems/ruby-2.1.2/gems/tripod-0.9.4/lib/tripod/streaming.rb:35:in `block in get_data'

The actual query (formatted) seems to be this:

SELECT * { 
  SELECT DISTINCT ?uri (<http://leipzig-data.de/Data/Strassenverzeichnis/> as ?graph) 
  WHERE {
    GRAPH <http://leipzig-data.de/Data/Strassenverzeichnis/> {
      ?uri a <http://leipzig-data.de/Data/Model/Strasse> . ?uri ?p ?o
    } 
  } 
} LIMIT 1

Which gives the error when I try it on the virtuoso console: http://www.leipzig-data.de:8890/sparql

I can confirm that @fonji 's fix actually works - at least in the console adding an extra brackets to the outer SELECT statement gives the correct results. But why, I don't understand...

It seems to be related to Virtuoso, because I got this working on a local instance of Fuseki.

Any ideas how this could be fixed?

lhm avatar Jul 01 '14 13:07 lhm

Just as an additional data point, here's the output from fuseki, when I run the following:

[2] pry(main)> Street.first
=> #<Street:0x00000101a6c780
 @graph_uri=#<RDF::URI:0x80d36190 URI:http://localhost:3030/ds/data/streets>,
 @new_record=false,
 @repository=#<RDF::Repository:0x80a25dfc()>,
 @uri=
  #<RDF::URI:0x80d36398 URI:http://leipzig-data.de/Data/Strasse/Maulbeerweg>>

Log:

15:51:08 INFO  [22] POST http://localhost:3030/ds/query
15:51:08 INFO  [22] Query = SELECT * { SELECT DISTINCT ?uri (<http://localhost:3030/ds/data/streets> as ?graph) WHERE { GRAPH <http://localhost:3030/ds/data/streets> { ?uri a <http://leipzig-data.de/Data/Model/Strasse> . ?uri ?p ?o } } } LIMIT 1
15:51:08 INFO  [22] exec/select
15:51:08 INFO  [22] 200 OK (5 ms) 
15:51:08 INFO  [23] POST http://localhost:3030/ds/query
15:51:08 INFO  [23] Query = DESCRIBE ?uri WHERE { SELECT * { SELECT DISTINCT ?uri (<http://localhost:3030/ds/data/streets> as ?graph) WHERE { GRAPH <http://localhost:3030/ds/data/streets> { ?uri a <http://leipzig-data.de/Data/Model/Strasse> . ?uri ?p ?o } } } LIMIT 1 }
15:51:08 INFO  [23] exec/describe
15:51:08 INFO  [23] 200 OK (5 ms) 
15:51:50 INFO  [24] GET http://localhost:3030/ds/query?query=DESCRIBE+%3Furi+WHERE+%7B+SELECT+*+%7B+SELECT+DISTINCT+%3Furi+%28%3Chttp%3A%2F%2Flocalhost%3A3030%2Fds%2Fdata%2Fstreets%3E+as+%3Fgraph%29+WHERE+%7B+GRAPH+%3Chttp%3A%2F%2Flocalhost%3A3030%2Fds%2Fdata%2Fstreets%3E+%7B+%3Furi+a+%3Chttp%3A%2F%2Fleipzig-data.de%2FData%2FModel%2FStrasse%3E+.+%3Furi+%3Fp+%3Fo+%7D+%7D+%7D+LIMIT+1+%7D&output=text&stylesheet=
15:51:50 INFO  [24] Query = DESCRIBE ?uri WHERE { SELECT * { SELECT DISTINCT ?uri (<http://localhost:3030/ds/data/streets> as ?graph) WHERE { GRAPH <http://localhost:3030/ds/data/streets> { ?uri a <http://leipzig-data.de/Data/Model/Strasse> . ?uri ?p ?o } } } LIMIT 1 }
15:51:50 INFO  [24] exec/describe
15:51:50 INFO  [24] 200 OK (17 ms)

lhm avatar Jul 01 '14 13:07 lhm

adding an extra brackets to the outer SELECT statement gives the correct results. But why, I don't understand...

I think point 4 of Virtuoso's documentation about subqueries kind of explains this. My guess is that you can select fields and a subquery, and they don't support the "subquery only" case.

fonji avatar Jul 01 '14 15:07 fonji