我正在尝试使用 SPARQL 从 Wikidata 中获取世界上最著名的电影。
我有以下查询:
SELECT ?item WHERE {
?item wdt:P31 wd:Q11424.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Run Code Online (Sandbox Code Playgroud)
返回所有电影(约 214143)。
我基本上只需要维基百科上有超过 10 种语言条目的电影,因为我猜这些将是最著名的。
有没有办法在查询本身内部执行此操作,而无需检查所有条目?
对您的问题的幼稚答案是:
SELECT ?movie (count(?wikipage) AS ?count) WHERE {
hint:Query hint:optimizer "None" .
?movie wdt:P31 wd:Q11424 .
?wikipage schema:about ?movie .
?wikipage schema:isPartOf/wikibase:wikiGroup "wikipedia"
} GROUP BY ?movie HAVING (?count > 10) ORDER BY DESC(?count)
Run Code Online (Sandbox Code Playgroud)
或者,您可以考虑附加链接的总数。附加链接包括指向维基百科的链接以及指向 Wikiquote、Wikivoyage 等的链接。优点是附加链接的总数是预先计算的。
SELECT ?movie ?sitelinks WHERE {
?movie wdt:P31 wd:Q11424 .
?movie wikibase:sitelinks ?sitelinks .
FILTER (?sitelinks > 10)
} ORDER BY DESC(?sitelinks)
Run Code Online (Sandbox Code Playgroud)
另请参阅以下问题:
正如@TallTed 和@AKSW 所指出的,不同语言的标签数量可能与不同语言的维基百科文章数量不同。下面来个对比。
维基百科文章中排名前 5 的电影
| title | articles | sitelinks | labels |
|---------------------|----------|-----------|--------|
| Avatar | 92 | 103 | 99 |
| Titanic | 86 | 100 | 101 |
| The Godfather | 79 | 103 | 82 |
| Slumdog Millionaire | 72 | 75 | 80 |
| Forrest Gump | 71 | 101 | 84 |
Run Code Online (Sandbox Code Playgroud)
附加链接排名前 5 的电影
| title | articles | sitelinks | labels |
|---------------|----------|-----------|--------|
| Avatar | 92 | 103 | 99 |
| The Godfather | 79 | 103 | 82 |
| Forrest Gump | 71 | 101 | 84 |
| Titanic | 86 | 100 | 101 |
| The Matrix | 67 | 94 | 77 |
Run Code Online (Sandbox Code Playgroud)
按标签分类的前 5 部电影
| title | articles | sitelinks | labels |
|------------------------------|----------|-----------|--------|
| The 25th Reich | 2 | 2 | 227 |
| Time Is But Brief | 0 | 0 | 224 |
| Michael Moore in TrumpLand | 6 | 6 | 222 |
| Magnus - The Mozart of Chess | 1 | 1 | 221 |
| Lee Chong Wei | 1 | 1 | 196 |
Run Code Online (Sandbox Code Playgroud)