Use Jena to request Wikidata

Wikidata currently has a SPARQL endpoint " https://query.wikidata.org/ ", I would like to query this site using Jena (3.0.1), I am using the following code, but I got the error message " Final the point returned by Content-Type: text / html, which is currently not supported for SELECT queries . " Is there any way to solve this problem? the same code works fine with dbpedia. Thanks

queryString = "PREFIX bd: <http://www.bigdata.com/rdf#>\n" + "PREFIX wikibase: <http://wikiba.se/ontology#>\n" + "PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n" + "PREFIX wd: <http://www.wikidata.org/entity/>\n" + "SELECT DISTINCT ?country ?countryLabel\n" + "WHERE\n" + "{\n" + "\t?country wdt:P31 wd:Q3624078 .\n" + " ?country wdt:P1622 wd:Q13196750.\n" + " ?country wdt:P30 wd:Q15\n" + "\tFILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}\n" + "\tSERVICE wikibase:label { bd:serviceParam wikibase:language \"en\" }\n" + "}\n" + "ORDER BY ?countryLabel"; query = QueryFactory.create(queryString); qexec = QueryExecutionFactory.sparqlService("https://query.wikidata.org/", queryString); try { ResultSet results = qexec.execSelect(); ResultSetFormatter.out(System.out, results, query); } catch (Exception ex) { System.out.println(ex.getMessage()); } finally { qexec.close(); } 
+4
source share
1 answer

According to the documentation , the endpoint has / sparql at the end. It says:

SPARQL queries can be sent directly to the SPARQL endpoint with a GET request at https://query.wikidata.org/sparql?query={SPARQL} (POST and other method queries will be denied with "403 Denied"). The result is returned as XML by default or as JSON if either the format = json request parameter or the Accept: application / sparql-results + json header is provided.

+7
source

All Articles