使用 dbpedia 作为终点向 jena (对于 sparql)添加超时?

发布于 2024-10-12 16:01:42 字数 257 浏览 2 评论 0原文

我想知道是否有办法使用 Jena 通过 dbpedia 进行 sparql 查询并使用 http: 中给出的超时设置: //dbpedia.org/sparql(如果您看到此页面,您可以看到有一种方法可以在那里设置超时),这是需要的,因为我想做一个大查询并且我已经尝试了几次有时(通过页面)不设置超时,我无法得到结果(它始终是事务超时异常)

编辑:我使用java.lang.

I would like to know whether there is a way to use Jena to do a sparql query through dbpedia and using the timeout setting given in http://dbpedia.org/sparql (if you see this page, you could see that there is a way to set the timeout there), this is needed since I would like to make a big query and I have tried several times (via the page) that without setting the timeout, I cannot get the result (it is always a transaction timeout exception)

edited: I use java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此岸叶落 2024-10-19 16:01:42

要执行您的查询,我猜您正在使用:

QueryExecutionFactory.sparqlService(String service, Query query) 

您可以尝试的一件事是:

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

似乎 QueryEngineHTTP 实现了 QueryExecution ,它有一个 addParam方法。没有对该方法的描述,但我假设它会向 HTTP 请求添加一个参数。

让我知道它是否有效!

已编辑
要修复错误,实际上是相反的... QueryEngineHTTP 实现 QueryExecution

To execute your query, I guess you're using :

QueryExecutionFactory.sparqlService(String service, Query query) 

One thing you could try is:

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's no description of that method but I'd assume that adds a parameter to the HTTP request.

Let me know if it works !!

Edited
to fix error actually it was the other way around ... QueryEngineHTTP implements QueryExecution

挖鼻大婶 2024-10-19 16:01:42

我会这样做:

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);

如果达到超时限制,则抛出 org.apache.jena.query.QueryCancelledException 。

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 it reached then a org.apache.jena.query.QueryCancelledException is thrown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文