gpt4 book ai didi

query-optimization - SPARQL 查询的优化。 [预计执行时间超过 1500(秒)的限制]

转载 作者:行者123 更新时间:2023-12-04 07:52:45 24 4
gpt4 key购买 nike

我正在尝试在 http://dbpedia.org/sparql 上运行此查询但我得到一个错误,我的查询太贵了。当我通过 http://dbpedia.org/snorql/ 运行查询时我得到:

The estimated execution time 25012730 (sec) exceeds the limit of 1500 (sec) ...

当使用 SPARQLWrapper 通过我的 python 脚本运行查询时,我只得到一个 HTTP 500。

我认为我需要做一些事情来优化我的 SPARQL 查询。我需要数据来遍历教育机构并将其导入本地数据库,也许我使用的 SPARQL 有误,应该以完全不同的方式执行此操作。

希望有人能帮助我!

查询

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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 skos: <http://www.w3.org/2004/02/skos/core#>

SELECT DISTINCT ?uri
?name
?homepage
?student_count
?native_name
?city
?country
?type
?lat ?long
?image

WHERE {
?uri rdf:type dbpedia-owl:EducationalInstitution .
?uri foaf:name ?name .
OPTIONAL { ?uri foaf:homepage ?homepage } .
OPTIONAL { ?uri dbpedia-owl:numberOfStudents ?student_count } .
OPTIONAL { ?uri dbpprop:nativeName ?native_name } .
OPTIONAL { ?uri dbpprop:city ?city } .
OPTIONAL { ?uri dbpprop:country ?country } .
OPTIONAL { ?uri dbpprop:type ?type } .
OPTIONAL { ?uri geo:lat ?lat . ?uri geo:long ?long } .
OPTIONAL { ?uri foaf:depiction ?image } .
}
ORDER BY ?uri
LIMIT 20 OFFSET 10

最佳答案

算了。仅使用一个 SPARQL 将无法从 dbpedia 返回该查询。那些可选项非常昂贵。

要解决这个问题,您需要先运行类似以下内容:

 SELECT DISTINCT ?uri WHERE {
?uri rdf:type dbpedia-owl:EducationalInstitution .
?uri foaf:name ?name .
} ORDER BY ?uri
LIMIT 20 OFFSET 10

然后遍历此查询的结果集,为每个 dbpedia-owl:EducationalInstitution 形成单个查询例如 ...(注意查询末尾的过滤器):

        SELECT DISTINCT ?uri
?name
?homepage
?student_count
?native_name
?city
?country
?type
?lat ?long
?image

WHERE {
?uri rdf:type dbpedia-owl:EducationalInstitution .
?uri foaf:name ?name .
OPTIONAL { ?uri foaf:homepage ?homepage } .
OPTIONAL { ?uri dbpedia-owl:numberOfStudents ?student_count } .
OPTIONAL { ?uri dbpprop:nativeName ?native_name } .
OPTIONAL { ?uri dbpprop:city ?city } .
OPTIONAL { ?uri dbpprop:country ?country } .
OPTIONAL { ?uri dbpprop:type ?type } .
OPTIONAL { ?uri geo:lat ?lat . ?uri geo:long ?long } .
OPTIONAL { ?uri foaf:depiction ?image } .
FILTER (?uri = <http://dbpedia.org/resource/%C3%89cole_%C3%A9l%C3%A9mentaire_Marie-Curie>)
}

在哪里<http://dbpedia.org/resource/%C3%89cole_%C3%A9l%C3%A9mentaire_Marie-Curie>已从第一个查询中获得。

... 是的,它会很慢,您可能无法为在线应用程序运行它。建议:尝试制定出某种缓存机制以位于您的应用程序和 dbpedia SPARQL 端点之间。

关于query-optimization - SPARQL 查询的优化。 [预计执行时间超过 1500(秒)的限制],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6280670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com