我正在尝试在JAVA中执行SPARQL查询,但在.execSelect()方法中得到了异常
我正在使用Apache Jena执行查询。我在pom.xml中添加的依赖项是
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-text</artifactId>
<version>3.0.0</version>
</dependency>
我正在尝试的代码(此查询在Virtuoso SparQL Query editor上完美运行)
String queryStr = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"PREFIX dbr: <http://dbpedia.org/resource/>\n" +
"SELECT ?uri ?label \n" +
" WHERE {?uri <http://purl.org/dc/terms/subject> ?categories .\n" +
"?categories rdfs:label ?label\n" +
" FILTER (?uri = dbr:Holy_Roman_Empire || ?uri = dbr:Part-of-speech_tagging || ?uri = dbr:Alt-Berlin || ?uri = dbr:Named-entity_recognition)\n" +
" FILTER (lang(?label) = 'en' || lang(?label) = 'de')\n" +
"}\n" +
"ORDER BY DESC(?uri)";
Query query = QueryFactory.create(queryStr);
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://dbpedia.org", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
我在qExe.execSelect()中得到的异常;是
线程“主”中的异常java.lang.NoSuchMethodError:org.apache.http.client.utils.URLEncodedUtils.format(Ljava / lang / Iterable; Ljava / nio / charset / Charset;)Ljava / lang / String;
我缺少一些依赖吗?