如何仅从维基数据 属性 中获取最新值?

How to get only the most recent value from a Wikidata property?

假设我想获得每个国家 (Q6256) 及其最近记录的人类发展指数 (P1081) 值的列表。该国家/地区的人类发展指数 属性 包含在不同时间点获取的数据点列表,但我只关心最近的数据。此查询将不起作用,因为它为每个国家/地区获取多个结果(每个人类发展指数数据点一个):

SELECT
?country 
?countryLabel 
?hdi_value
?hdi_date
WHERE {
  ?country wdt:P31 wd:Q6256.
  OPTIONAL { ?country p:P1081 ?hdi_statement. 
         ?hdi_statement ps:P1081 ?hdi_value.
         ?hdi_statement pq:P585 ?hdi_date.
       }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Link to Query Console

我知道 GROUP BY/GROUP CONCAT,但当我只想得到一个结果时,它仍然会为我提供所有结果。 GROUP BY/SAMPLE 也将不起作用,因为不能保证 SAMPLE 会采用最新结果。

对相关示例查询的任何帮助或link表示感谢!

P.S。我感到困惑的另一件事是为什么此查询中的人口 P1082 returns 每个国家/地区只有一个人口结果

SELECT
?country 
?countryLabel 
?population
WHERE {
  ?country wdt:P31 wd:Q6256.
  OPTIONAL { ?country wdt:P1082 ?population. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

虽然查询相同但 HDI returns 每个国家/地区有多个结果:

SELECT
?country 
?countryLabel 
?hdi
WHERE {
 ?country wdt:P31 wd:Q6256.
  OPTIONAL { ?country wdt:P1081 ?hdi. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

导致行为不同的人口和 HDI 有何不同?当我在 Wikidata 上查看每个国家/地区的人口数据时,我看到列出了多个人口点,但查询只返回一个点。

你的两个问题都是重复的,但我会尝试在现有答案中添加有趣的事实。

问题 1 重复。

这项技术可以解决问题:

FILTER NOT EXISTS {
    ?country p:P1081/pq:P585 ?hdi_date_ .
    FILTER (?hdi_date_ > ?hdi_date)
}

但是,您应该在 OPTIONAL 外部 添加此子句,它在 OPTIONAL 内部不起作用(我不确定这是不是不是错误)。


问题 2

重复

您不能使用 wdt-predicates,因为缺少的语句不 真实
它们是 normal-rank 语句,但是有一个 preferred-rank 语句。

Truthy statements represent statements that have the best non-deprecated rank for given property. Namely, if there is a preferred statement for property P2, then only preferred statements for P2 will be considered truthy. Otherwise, all normal-rank statements are considered truthy.

之所以P1081一直有preferred语句,是因为这个属性被PreferentialBot处理了。