我是将SPARQL用于Wikidata的初学者。我用它通过代码获取具有特定死亡日期的人的数据列表:
SELECT ?human ?humanLabel ?humanDescription ?gender ?birth_date ?death_date ?bplace ?dplace ?img ?prof ?profLabel ?article WHERE {
?human wdt:P31 wd:Q5;
wdt:P18 ?img;
wdt:P19 ?bplace;
wdt:P20 ?dplace;
wdt:P21 ?gender;
wdt:P569 ?birth_date;
wdt:P570 ?death_date;
#rdfs:label ?name;
#schema:description ?description;
wdt:P106 ?prof.
?article schema:about ?human .
?article schema:inLanguage "en".
FILTER (year(?death_date) = 2020)
#FILTER(!REGEX(STR(?article), "^<https://en.wikipedia.org/"))
SERVICE wikibase:label {bd:serviceParam wikibase:language "en".}
}
ORDER BY ASC(?death_date)
但是响应中有一些重复项(并使响应变大)。另外,我只需要接收来自en.wikipedia.org的文章中的Wikipedia数据,但是FILTER(!REGEX(STR(?article), "^<https://en.wikipedia.org/"))
会使查询速度变慢。
我该如何解决?
您的查询有问题:
?article schema:isPartOf <https://en.wikipedia.org/> .
而不是过滤,这是更快的结果查询运行不到30秒:https://w.wiki/UN8
通常来说,最好首先编写一个简单,快速的查询,以给出所有结果,然后加载其他数据,最后加载标签和描述。