代码之家  ›  专栏  ›  技术社区  ›  Wolfgang Fahl

Wikidata LabelService的行为不符合预期

  •  2
  • Wolfgang Fahl  · 技术社区  · 8 年前

    以下Wikidata查询无法正常工作:

    # WikiData SPARQL Query
    #
    # Wolfgang Fahl 2018-01-06
    #
    # get father of queen victoria
    SELECT ?queenVictoria ?queenVictoriaLabel ?fatherProperty ?fatherPropertyLabel ?father ?fatherLabel
    WHERE {
    #  
    # father
    # https://www.wikidata.org/wiki/Property:P42
    # Queen Victoria
    # https://www.wikidata.org/wiki/Q9439
      BIND (wdt:P22 AS ?fatherProperty).
      BIND (wd:Q9439 AS ?queenVictoria).
      ?queenVictoria ?fatherProperty ?father.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    

    try it!

    结果是

    queenVictoria queenVictoriaLabel fatherProperty fatherPropertyLabel                     father.      fatherLabel   
    wd:Q9439      Queen Victoria     wdt:P22        http://www.wikidata.org/prop/direct/P22 wd:Q157009   Prince Edward Augustus, Duke of Kent and Strathearn
    

    我原以为标签会是维多利亚女王、父亲和“爱德华·奥古斯都王子”。

    我的问题是什么?还是这是一个bug?

    1 回复  |  直到 8 年前
        1
  •  3
  •   Stanislav Kralin kenwenzel    8 年前

    原因是 http://www.wikidata.org/prop/direct/P22 返回而不是 father 维基数据是真的吗 predicates 没有标签(请尝试 DESCRIBE wdt:P22 ). 仅适用于适当的 properties 有标签(试试 DESCRIBE wd:P22 ).

    维基数据 label service doesn't :

    SERVICE wikibase:label 仅为wd中的实体提供标签: 名称空间。

    因此 try 此查询:

    SELECT ?queenLabel ?realpropertyLabel ?fatherLabel
    WHERE {
      VALUES (?queen) {(wd:Q9439)}
      VALUES (?property) {(wdt:P22)}
      ?queen ?property ?father .
      ?realproperty wikibase:directClaim ?property
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }