0

I have (almost) the same problem as here. But I couldn't figure out how to apply it to my problem. I want to convert a SPARQL query to its algebra expression. So the example code:

Query query = QueryFactory.create(args[0]);
Op op = Algebra.compile(query) ;
System.out.println(op);

However, as Joshua said: Virtuoso accepts non-standard SPARQL and Jena does not.. error is:

Exception in thread "main" org.apache.jena.query.QueryParseException: Encountered " "<" "< "" at line 1, column 14.

manually correcting the query isn't really a solution, as I want to do this with a few hundred queries... Thanks for your help

EDIT:

sample query:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
SELECT * 
WHERE 
  { 
    {?city rdfs:label 'Tapiramutá'@en.} 
  UNION 
    { ?alias <http://dbpedia.org/property/redirect> ?city;
      rdfs:label 'Tapiramutá'@en. } 
  UNION 
    {?alias <http://dbpedia.org/property/disambiguates> ?city;
     rdfs:label 'Tapiramutá'@en. } 
OPTIONAL { ?city <http://dbpedia.org/ontology/abstract> ?abstract}
OPTIONAL { ?city geo:lat ?latitude; geo:long ?longitude}
OPTIONAL { ?city foaf:depiction ?image } 
OPTIONAL { ?city rdfs:label ?name } 
OPTIONAL { ?city foaf:homepage ?home } 
OPTIONAL { ?city <http://dbpedia.org/ontology/populationTotal> ?population } 
OPTIONAL { ?city <http://dbpedia.org/ontology/thumbnail> ?thumbnail } FILTER (langMatches( lang(?abstract), 'en'))}
Community
  • 1
  • 1
dv3
  • 4,369
  • 5
  • 28
  • 50
  • That does not work. Jena needs to parse the query String to create a query object. And Jena follows the official SPARQL 1.1 specs. Which query does not work? – UninformedUser Feb 19 '17 at 16:23
  • that is really unfortunate... I've added a query where Virtuoso (dbpedia.org) executes the query and Jena / the sparql query validator have issues. – dv3 Feb 19 '17 at 16:32
  • on a second glance: this seems to be largely an issue of missing prefixes.. dbpedia has a lot of namespaces predefined (https://dbpedia.org/sparql?nsdecl) that jena is missing... – dv3 Feb 19 '17 at 16:37
  • Right, in your query prefix declarations are missing. As a workaround, you can automatically prepend a prefix declaration string that contains as many prefixes as possible. But that's not a problem of Jena and prefixes are necessary the resolve the full URIs. We also added some workaround when we tried to parse the DBpedia query log, annoying, but it works to some extend. – UninformedUser Feb 19 '17 at 17:01

0 Answers0