【问题标题】:Wikidata Query Service traverse property维基数据查询服务遍历属性
【发布时间】:2016-07-28 10:43:58
【问题描述】:

我正在尝试获取给定 Wikidata 项目的所有超名称的列表。 例如,我想遍历 https://www.wikidata.org/wiki/Q4421 的“子类”元素。

https://query.wikidata.org 的 SPARQL 命令是什么样的?

【问题讨论】:

    标签: sparql wikidata-query-service


    【解决方案1】:

    您可以使用属性路径 (*) 语法。

    在这种情况下,wdt:P279* 提到 0 次或更多次 wdt:P279,它是 Wikidata 模型中等价物的子类。

    我在这里添加了一些变体以包括深度,以便您可以订购它们

    SELECT ?entity ?entityLabel (count(?mid) as ?depth) WHERE {
      wd:Q4421 wdt:P279* ?mid.
      ?mid wdt:P279* ?entity
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
    } group by ?entity ?entityLabel
    order by ?depth
    

    https://query.wikidata.org/#SELECT%20%3Fentity%20%3FentityLabel%20%28count%28%3Fmid%29%20as%20%3Fdepth%29%20WHERE%20%7B%0A%20%20wd%3AQ4421%20wdt%3AP279%2a%20%3Fmid.%0A%20%20%3Fmid%20wdt%3AP279%2a%20%3Fentity%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20.%0A%20%20%20%7D%0A%7D%20group%20by%20%3Fentity%20%3FentityLabel%0Aorder%20by%20%3Fdepth

    【讨论】:

      【解决方案2】:

      刚刚找到了一个可以解决我的问题的工具。 https://angryloki.github.io/wikidata-graph-builder/?property=P279&item=Q4421

      【讨论】:

        【解决方案3】:

        你可以使用 SPARQL 递归语法*:

        SELECT ?entity WHERE {
          wd:Q4421 wdt:P279* ?entity.
        }
        

        see on query.wikidata.org

        【讨论】:

          猜你喜欢
          • 2018-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多