【问题标题】:How to get the number of languages a Wikipedia page is available in? (SPARQL query)如何获取维基百科页面可用的语言数量? (SPARQL 查询)
【发布时间】:2021-08-26 16:06:17
【问题描述】:

我正在尝试获取 1980 年以来的意大利书籍列表以及其原始 Wikipedia 页面已被翻译成的 Wikipedia 页面数量,例如,我想要:

Book, number
The name of the Rose, 5

其中 5 是“玫瑰之名”在维基百科中被翻译成的语言数量,例如,有一个英语 wiki 页面、一个荷兰语、一个西班牙语、一个法语、一个希腊语。

这是目前的查询:

SELECT ?item ?label 
WHERE
{
  VALUES ?type {wd:Q571 wd:Q7725634}  # book or literary work
  ?item wdt:P31 ?type .
  ?item wdt:P577 ?date FILTER (?date > "1980-01-01T00:00:00Z"^^xsd:dateTime) . #dal 1980
  ?item rdfs:label ?label filter (lang(?label) = "it")
  ?item wdt:P495 wd:Q38 .


}

我得到了图书清单,但找不到合适的财产。

【问题讨论】:

  • SELECT ?item ?label (count(?lang) as ?numWikipediaLanguages) WHERE { hint:Query hint:optimizer "None". VALUES ?type {wd:Q571 wd:Q7725634} # book or literary work ?item wdt:P31 ?type . ?item wdt:P577 ?date . hint:Prior hint:rangeSafe "true" . FILTER (?date > "1980-01-01T00:00:00Z"^^xsd:dateTime) . #dal 1980 ?item rdfs:label ?label filter (lang(?label) = "it") ?item wdt:P495 wd:Q38 . ?article schema:about ?item ; schema:inLanguage ?lang ; schema:isPartOf [ wikibase:wikiGroup "wikipedia" ] . } group by ?item ?label
  • 非常感谢!我想知道,我只得到了大约 400 件物品,但它们肯定更多......
  • 您会说哪些示例缺少?我的意思是最终取决于维基数据中的数据

标签: sparql wikipedia wikipedia-api wikidata


【解决方案1】:

在你的例子中你真的得到了玫瑰的名字吗?因为它的发布日期设置为1980(我们的目的是= 1980-01-01),所以我不得不将您的查询更改为>= 比较。

然后,使用评论中提到的COUNT()GROUP BY 可以得到你想要的。但是,如果您真的只需要站点链接的数量,那么有一个捷径可能会很有用。之所以添加它,是因为该数字通常用作衡量项目受欢迎程度的良好指标,并且使用预先计算的数字比获取所有链接、分组和计数要高效得多。

SELECT ?book ?bookLabel ?sitelinks ?date WHERE {
  VALUES ?type { wd:Q571 wd:Q47461344 wd:Q7725634 }
  ?book wdt:P31 ?type;
        wdt:P577 ?date;
        wdt:P495 wd:Q38;
        wikibase:sitelinks ?sitelinks.
  FILTER((?date >= "1980-01-01T00:00:00Z"^^xsd:dateTime) && (?date < "1981-01-01T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en". }
}

Query

请注意,这些值可能与带有 group 和 count 的版本略有不同,因为这里还包括 commonswikiquote 等网站。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多