Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to Virtuoso Openlink Sparql Endpoint #20

Open
samuraraujo opened this issue Oct 1, 2013 · 6 comments
Open

Support to Virtuoso Openlink Sparql Endpoint #20

samuraraujo opened this issue Oct 1, 2013 · 6 comments

Comments

@samuraraujo
Copy link

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

@BillSwirrl
Copy link
Member

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
Copy link
Member

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.

@fonji
Copy link

fonji commented Nov 6, 2013

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

@lhm
Copy link

lhm commented Jul 1, 2014

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
Copy link

lhm commented Jul 1, 2014

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)

@fonji
Copy link

fonji commented Jul 1, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants