The URL is sending back HTML.
Probably means it is a URL to a form for asking SPARQL queries, not the
SPARQL endpoint itself. See if you can find out where the form sends
the query.
Andy
On 09/04/2020 14:29, Luis Enrique Ramos García wrote:
Andy,
In addition I am working in another end point, and now I am getting this
output:
Endpoint returned Content-Type: text/html which is not rcognized for SELECT
queries
I followed this recommendation
https://stackoverflow.com/questions/41926530/jena-endpoint-returned-content-type-text-html
however the behavior does not change, and I continue receiving this error:
Exception in thread "main" org.apache.jena.query.QueryException: Endpoint
returned Content-Type: text/html which is not rcognized for SELECT queries
at
org.apache.jena.sparql.engine.http.QueryEngineHTTP.execResultSetInner(QueryEngineHTTP.java:377)
at
org.apache.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:345)
at
ag.pst.jena.test.RDFConnectionExample4.main(RDFConnectionExample4.java:84)
any recommendation?
Luis
El jue., 9 abr. 2020 a las 15:03, Andy Seaborne (<a...@apache.org>)
escribió:
"SELECT ?item1 WHERE {\n" +
" ?item1 wdt:P31 ?item2.\n" +
"} LIMIT 10";
qs1.getResource("s")
The variable is called "item1"
qs1.getResource("item1")
Andy
On 09/04/2020 13:47, Luis Enrique Ramos García wrote:
dear member of jena community,
I have been trying to query wikidata following the documentation [1] and
other examples I have found, but result obtained has been null values,
besides it is a simple query, that I have just previously tested in the
wikidata query GUI.
I followed two methods, one with QueryExecution, and another
with RDFConnectionRemote, but however in both the output is null as well.
Please, let me know if I am missing something, or if I am going in the
wrong direction.
Best regards
Luis Ramos
*CODE *
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdfconnection.RDFConnection;
import org.apache.jena.rdfconnection.RDFConnectionFactory;
import org.apache.jena.rdfconnection.RDFConnectionRemote;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/*
* Example of a building a remote connection.
*/
public class RDFConnectionExample4 {
//testing
static Logger log = Logger.getLogger(RDFConnectionExample4.class);
public static void main(String ...args) {
log.setLevel(Level.INFO);
log.info("This is Luis Logger");
BasicConfigurator.configure();
String my_query = "PREFIX schema: <http://schema.org/>\n" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" +
"PREFIX hist: <http://wikiba.se/history/ontology#>\n" +
"PREFIX wd: <http://www.wikidata.org/entity/>\n" +
"PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n" +
"PREFIX wikibase: <http://wikiba.se/ontology#>\n" +
"PREFIX dct: <http://purl.org/dc/terms/>\n" +
"\n" +
"SELECT ?item1 WHERE {\n" +
" ?item1 wdt:P31 ?item2.\n" +
"} LIMIT 10";
System.out
.println("The query string is"+ my_query);
Query query = QueryFactory.create(my_query);
//method 1 with query execution
QueryExecution qe1 = QueryExecutionFactory.sparqlService("
https://query.wikidata.org/sparql", query);
ResultSet rs1 = qe1.execSelect() ;
while(rs1.hasNext()) {
QuerySolution qs1 = rs1.next() ;
Resource subject1 = qs1.getResource("s") ;
System.out.println("Subject: "+subject1) ;
}
//method 2
RDFConnection conn0 = RDFConnectionRemote.create()
.destination("https://query.wikidata.org/")
.queryEndpoint("sparql")
// Set a specific accept header; here, sparql-results+json
(preferred) and text/tab-separated-values
//The default is "application/sparql-results+json,
application/sparql-results+xml;q=0.9, text/tab-separated-values;q=0.7,
text/csv;q=0.5, application/json;q=0.2, application/xml;q=0.2, */*;q=0.1"
.acceptHeaderSelectQuery("application/sparql-results+json,
application/sparql-results+xml;q=0.9")
.build();
String queryService = "https://query.wikidata.org/sparql?";
RDFConnection conn = RDFConnectionFactory.connect(queryService,
null, null);
QueryExecution qe2 = conn.query(query);
ResultSet rs2 = qe2.execSelect() ;
while(rs2.hasNext()) {
QuerySolution qs2 = rs2.next() ;
Resource subject2 = qs2.getResource("s") ;
System.out.println("Subject: "+subject2) ;
}
// QueryExecution qExec = conn.query(query);
}
https://jena.apache.org/documentation/rdfconnection/