简单的 sparql 查询不起作用,日期比较
对于以下简单查询,我在 dbpedia sparql 端点上收到“SR171:事务超时”:为什么会收到此错误?我没有设置任何超时 - 它是 0。
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX ont: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?date (bif:substring(STR(?date), 1, 4) AS ?year) WHERE {
?person ont:birthDate ?date .
?person foaf:name ?name
. FILTER ( (fn:string-length(STR(?date)) = 10) && (bif:substring(STR(?date), 9, 2) = '05') && (bif:substring(STR(?date), 6, 2) = '02') && (?date > "1868-01-01"^^xsd:date) && (?date < "2005-01-01"^^xsd:date) )
I get "SR171: Transaction timed out" on the dbpedia sparql endpoint, for the following simple query: Why do I get this error? I don't set any timeout - it's on 0.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX ont: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?date (bif:substring(STR(?date), 1, 4) AS ?year) WHERE {
?person ont:birthDate ?date .
?person foaf:name ?name
. FILTER ( (fn:string-length(STR(?date)) = 10) && (bif:substring(STR(?date), 9, 2) = '05') && (bif:substring(STR(?date), 6, 2) = '02') && (?date > "1868-01-01"^^xsd:date) && (?date < "2005-01-01"^^xsd:date) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您的查询对于 DBPedia 端点来说太难回答,而不会对服务的其他用户产生不利影响。
由于 DBPedia 是一个众所周知的公共 SPARQL 端点,因此它的使用非常频繁,因此托管它的人将其配置为对查询可以运行的时间施加严格限制,以便恶意用户不会使该服务对其他人无法使用。
在您的情况下,您的查询将花费很长时间,因为您询问的内容有很多初始结果(准确地说是 592299),然后对其应用
FILTER
。FILTER
在 SPARQL 中非常昂贵,尤其是在进行字符串操作和日期比较时。据我所知,DBPedia 超时相当低,例如几秒钟,端点根本无法在这段时间内完成查询,因为应用FILTER
需要很长时间。注意 - 这是我用来查看查询的第一部分返回了多少结果的查询:
It's because your query is too hard for the DBPedia endpoint to answer without adversely impacting other users of the service.
As DBPedia is a well known public SPARQL endpoint it gets very heavily used so the people who host it have it configured to impose strict limits on how long a query can run for so that rogue users don't make the service unusable for others.
In your case your query will take a long time because you ask something that has a lot of initial results (592299 to be precise) and then apply a
FILTER
over it.FILTER
is quite expensive in SPARQL especially when doing string manipulation and date comparison. AFAIK the DBPedia timeout is something fairly low like a few seconds and the endpoint simply cannot finish your query within that time because it takes too long to apply theFILTER
.Note - Here's the query I used to see how many results the first portion of your query was returning: