Wikidata LabelService表现不符预期,SPARQL查询标签异常求助
Hey there! Let's break down why your query isn't returning the label you expect for the fatherProperty field—it's not a bug, just a small adjustment needed in how you reference the property in your query.
The Root Issue
Your current query binds wdt:P22 to ?fatherProperty. The wdt: namespace points to direct property IRIs (like the raw URL you saw in results), but the wikibase:label service is built to fetch human-readable labels for property entities, which use the wd: namespace (i.e., wd:P22). When you pass the direct property IRI to the label service, it can't resolve the friendly label and returns the raw URL instead.
The Corrected Query
Adjust your query to bind the property entity (wd:P22) to ?fatherProperty, while still using the direct property (wdt:P22) in the triple pattern to fetch the father relationship. Here's the fixed version:
# WikiData SPARQL Query # # Wolfgang Fahl 2018-01-06 # # get father of queen victoria SELECT ?queenVictoria ?queenVictoriaLabel ?fatherProperty ?fatherPropertyLabel ?father ?fatherLabel WHERE { # father # Queen Victoria BIND (wd:P22 AS ?fatherProperty). BIND (wd:Q9439 AS ?queenVictoria). ?queenVictoria wdt:P22 ?father. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
What This Fixes
wd:P22is the official property entity for "father", so the label service will correctly return"father"for?fatherPropertyLabel.wdt:P22stays in the triple pattern to ensure we still fetch the correct father-child relationship between Queen Victoria and her father.
Expected Results
After running the corrected query, your output will match your expectations:
queenVictoria | queenVictoriaLabel | fatherProperty | fatherPropertyLabel | father | fatherLabel wd:Q9439 | Queen Victoria | wd:P22 | father | wd:Q157009| Prince Edward Augustus, Duke of Kent and Strathearn
内容的提问来源于stack exchange,提问作者Wolfgang Fahl

