Adding a timeout to jena (for sparql) using dbpedia as an endpoint?

I would like to know if there is a way to use Jena to execute a sparql request via dbpedia and use the timeout given at http://dbpedia.org/sparql (if you see this page, you can see that there is a way to set the time there expectations), this is necessary, since I would like to make a big request, and I tried several times (through the page) that without setting a timeout, I can not get the result (this is always an exception to the transaction timeout)

edited: I use java.

+4
source share
2 answers

To fulfill your request, I think you are using:

QueryExecutionFactory.sparqlService(String service, Query query) 

One thing you could try:

 QueryEngineHTTP objectToExec=QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",YOUR_QUERY); objectToExec.addParam("timeout","5000"); //5 sec resultset=objectToExec.execSelect(); 

It seems that QueryEngineHTTP implements QueryExecution , which has an addParam method. There is no description of this method, but I would suggest that it adds a parameter to the HTTP request.

Let me know if this works!

Edited to fix the error, in fact it was the other way around ... QueryEngineHTTP implements QueryExecution

+3
source

I would do it like this:

 String service = "http://dbpedia.org/sparql"; QueryExecution qexec = QueryExecutionFactory.create(query, service) ; qexec.setTimeout(10, TimeUnit.MINUTES); ResultSet results = qexec.execSelect() ; String result = ResultSetFormatter.asText(results); 

If, if the timeout limit is reached, then an org.apache.jena.query.QueryCancelledException is thrown.

0
source

Source: https://habr.com/ru/post/1336068/


All Articles