Hey all,

Using Jena, I frequently run into trouble where I need to run a non-standard sparql that is rejected by Jena's parser, even though it works fine when I submit it manually to Virtuoso's sparql endpoint. For example, the following query works fine on virtuoso:

SELECT ?p, (count (*) as ?count) WHERE { ?s ?p ?o } GROUP BY ?p

and this one too:

SELECT DISTINCT bif:iri_split(?p) WHERE { ?s ?p ?o . } LIMIT 100

But when I run either through Jena I get an exception like this:

  com.hp.hpl.jena.query.QueryParseException: Encountered " "," ", "" at line 1, column 10.
  Was expecting one of:
    <VAR1> ... <VAR2> ... "from" ... "where" ... "{" ...
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53)
at com.hp.hpl.jena.sparql.lang.Parser.parse(Parser.java:37)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:156)

Here is the code I used:

    String endpoint = "http://localhost:8890/sparql";
    String query = "SELECT ?p, (count (*) as ?count) WHERE ?s ?p ?o } GROUP BY ?p";
QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, query);

I'm using Jena 2.7.4 and Virtuoso OSE 6.1.3127

Can I tell Jena to fore go checking my SPARQL query and just send it straight to Virtuoso? Or is there any other way around this problem?

asked 05 Dec '12, 09:42

amarillion's gravatar image

amarillion
255
accept rate: 0%


SELECT ?p, (count (*) as ?count) WHERE { ?s ?p ?o } GROUP BY ?p

SPARQL does not have "," in select lists.

SELECT DISTINCT bif:iri_split(?p) WHERE { ?s ?p ?o . } LIMIT 100

bif: is virtuoso specific syntax and not in the SPARQL 1.1. grammar. Also, every expression needs an AS and variable name. "Embrace and extend".

You can create a QueryEngineHTTP object directly (used by QueryExecutionFactory.sparqlService) and pass it the query string.

permanent link

answered 05 Dec '12, 10:21

AndyS's gravatar image

AndyS ♦
13.6k37
accept rate: 33%

You're right about the comma, I missed that one. For the other query, unfortunately I'm stuck with using Virtuoso's non-standard extensions. Anyway, using QueryEngineHTTP solves this problem for me!

(05 Dec '12, 12:02) amarillion amarillion's gravatar image

Another way you can get queries using Virtuoso bif extensions to be seen as valid SPARQL (because as Andy points out they aren't) is to enclose calls to bif functions in < > as if they were URIs. This way standards compliant SPARQL parsers just treat them as IRIs in an unknown scheme and Virtuoso still interprets them as it's extensions e.g.

<bif:iri_split>
permanent link

answered 05 Dec '12, 12:10

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.9k1715
accept rate: 29%

To elaborate on AndyS' answer, here is the code that I used in the end:

String endpoint = "http://localhost:8890/sparql";
String query = "SELECT ?p, (count (*) as ?count) WHERE ?s ?p ?o } GROUP BY ?p";
QueryEngineHTTP qe = new QueryEngineHTTP(endpoint, query);
ResultSet rs = qe.execSelect();
permanent link

answered 05 Dec '12, 12:03

amarillion's gravatar image

amarillion
255
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1,305
×617
×199

question asked: 05 Dec '12, 09:42

question was seen: 1,333 times

last updated: 05 Dec '12, 12:10