DBpedia Jena Query returning null

安稳与你 提交于 2019-11-26 04:27:41

问题


I\'m just trying to run a small query on DBpedia, the query itself works, see it here, but I don\'t why its returning when doing so with Jena, I\'m getting null.

String service = \"http://dbpedia.org/sparql\";
String queryString = \"\";
queryString = \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label\" +
        \"WHERE {\" +
        \"<http://dbpedia.org/resource/Quatre_Bornes> <http://dbpedia.org/ontology/country> ?y .\"+
        \"?y rdfs:label ?label .\"+ 
        \"FILTER (LANG(?label) = \'en\')\"+
        \"}\";

Query query = QueryFactory.create(queryString);
QueryEngineHTTP qexec = QueryExecutionFactory.createServiceRequest(service, query);
ResultSet results = qexec.execSelect();
for ( ; results.hasNext() ; ) {
    QuerySolution soln = results.nextSolution() ;
    System.out.println(soln.getLiteral(\"label\"));
}

Any suggestion?


回答1:


that is so embarassing, there is space problem in the query:

String service = "http://dbpedia.org/sparql";
        String queryString = "";
        queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label " +
            "WHERE {" +
             "<http://dbpedia.org/resource/Quatre_Bornes> <http://dbpedia.org/ontology/country> ?y ."+
             "?y rdfs:label ?label ."+ 
             "FILTER (LANG(?label) = 'en')"+
            "}";


来源:https://stackoverflow.com/questions/15663510/dbpedia-jena-query-returning-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!