HttpException 400 SPARQL in Java

271 views Asked by At

I'm trying to write a query that will search dbpedia movies only and find movies with the keyword "Inception". The query is working on http://dbpedia.org/sparql but not in my java code. I'm using jena libraries.

This is my Query

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?Concept where {
?Concept a dbpedia-owl:Film.
?Concept rdfs:label ?label. FILTER (strStarts(str(?label), 'Inception')). } limit 10

Here is my Java function

public static String extractDbpedia (String jenaString) {
    String result;
    String queryString =
            "prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>" +
            "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
            "prefix dbpedia-owl:<http://dbpedia.org/ontology/>" +
            "prefix xsd: <http://www.w3.org/2001/XMLSchema#>" +
            "SELECT * WHERE { " +
            "    SERVICE <http://141.117.3.88:8890/sparql> { " +
            "select ?Concept where { ?Concept a dbpedia-owl:Film. ?Concept rdfs:label ?label. FILTER (strStarts(str(?label), 'Inception')). } limit 10" +
            "    }" +
            "}" ;
    LogCtl.setCmdLogging();
    Query query = QueryFactory.create(queryString) ;
    try(QueryExecution qexec = QueryExecutionFactory.create(query, ModelFactory.createDefaultModel())) {
        ResultSet rs = qexec.execSelect();
        result = (ResultSetFormatter.asText(rs));
    }
    return result;

I am getting Error HttpException: 400 and I don't know why. Thanks!

1

There are 1 answers

2
Joshua Taylor On

Your query may work at DBpedia, but the part that's supposed to be executed on http://141.117.3.88:8890/sparql doesn't work at http://141.117.3.88:8890/sparql. If you try running

prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select ?Concept where {
  ?Concept a dbpedia-owl:Film.
  ?Concept rdfs:label ?label.
  FILTER (strStarts(str(?label), 'Inception')).
}

SPARQL Results (an error message)

there, you get:

Virtuoso 37000 Error SP030: SPARQL compiler, line 11: syntax error at 'strStarts' before '('

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select ?Concept where {
  ?Concept a dbpedia-owl:Film.
  ?Concept rdfs:label ?label.
  FILTER (strStarts(str(?label), 'Inception')).
}

The about text for the server says:

Copyright © 2015 OpenLink Software Virtuoso version 06.01.3127 on Linux (x86_64-pc-linux-gnu), Single Server Edition

Perhaps that version of Virtuoso doesn't support all the SPARQL 1.1 functions? You'd need to check the Virtuoso documentation, but based on Does Virtuoso versions <=6.0 support SPARQL 1.1?, it sounds like the version you've got, 6.01, may not support SPARQL 1.1 completely. The public DBpedia endpoint, on the other hand, is running a 7.x version:

Copyright © 2015 OpenLink Software Virtuoso version 07.20.3213 on Linux (x86_64-redhat-linux-gnu-FX2), Single Server Edition