Wikidata LabelService does not behave as expected

断了今生、忘了曾经 提交于 2019-11-27 08:19:55

问题


The following Wikidata query does not work as I would expect it:

# 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!

The result is

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

I was expecting the labels to be Queen Victoria, father and "Prince Edward Augustus".

Whats wrong with my query? Or is this a bug?


回答1:


The reason why http://www.wikidata.org/prop/direct/P22 is returned instead of father is that Wikidata truthy predicates do not have labels (try DESCRIBE wdt:P22). Only proper properties have labels (try DESCRIBE wd:P22).

Wikidata label service could wrap this situation, but it doesn't:

SERVICE wikibase:label only supplies labels for entities in the wd: namepace.

Thus, try this query:

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". }
} 


来源:https://stackoverflow.com/questions/48338287/wikidata-labelservice-does-not-behave-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!