You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wikidata SPARQL查询1月1日出生日期数据异常问题求助

Wikidata SPARQL查询1月1日出生知名人士的异常问题与解决

问题描述

我想用Wikidata SPARQL按出生日期查询知名人士,一年中其他日期的查询都正常,但1月1日的查询存在异常:

  • 系统会将仅记录“年份+月份”的日期自动填充为当月1日(比如“1980年1月”会被转成“1980年1月1日”);
  • 不添加时间精度过滤时,会返回非1月1日出生的人员(例如Joy Reid,实际生日是12月8日);
  • 添加时间精度值为12的过滤后,又没有任何结果返回。
    想问是否无法通过Wikidata SPARQL获取1月1日出生人员的出生日期数据?

原查询代码

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel (GROUP_CONCAT(DISTINCT ?occupationLabel; separator=", ") as ?occupations)
WHERE {
  VALUES ?country {wd:Q30 wd:Q145}
  ?person wdt:P31 wd:Q5 ;  # Instance of human
    wdt:P569 ?birthdate ;  # Date of birth
    wdt:P27 ?country ;  # Citizenship
    wdt:P8687 ?followers; # Social Media Followers 
    wdt:P106 ?occupation ;  # Occupation
    wdt:P18 ?uniqueImage .  # Image;

  FILTER(MONTH(?birthdate) = 1  && DAY(?birthdate) = 1)
  FILTER(LANG(?occupationLabel) = "en")
  ?occupation rdfs:label ?occupationLabel .

  ?birthdate wikibase:timePrecision "12"^^xsd:integer .  #remove this to have results come back (though wrong like Joy Reid)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel
ORDER BY DESC(?followers)
LIMIT 40

解决方案

不是无法获取,问题出在对Wikidata时间精度值的理解偏差,以及过滤逻辑错误:

  1. Wikidata时间精度对应规则:

    • 精度值9:仅精确到年份
    • 精度值10:精确到年+月
    • 精度值11:精确到年+月+日
    • 精度值12及以上:精确到小时、分钟等更细粒度

    原查询用12作为精度过滤条件,但绝大多数仅记录到“日”的生日数据,精度值是11而非12,这直接导致符合条件的真实结果被过滤掉。

  2. 修正后的查询逻辑:

    • 保留月日为1月1日的过滤条件
    • 将精度过滤调整为精度≥11,这样既能排除那些仅精确到年/月、被系统自动填充1日的无效数据,又能包含所有精确到日及更细粒度的真实生日记录

修正后的查询代码:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel (GROUP_CONCAT(DISTINCT ?occupationLabel; separator=", ") as ?occupations)
WHERE {
  VALUES ?country {wd:Q30 wd:Q145}
  ?person wdt:P31 wd:Q5 ;
    wdt:P569 ?birthdate ;
    wdt:P27 ?country ;
    wdt:P8687 ?followers;
    wdt:P106 ?occupation ;
    wdt:P18 ?uniqueImage .

  FILTER(MONTH(?birthdate) = 1 && DAY(?birthdate) = 1)
  FILTER(LANG(?occupationLabel) = "en")
  ?occupation rdfs:label ?occupationLabel .

  # 过滤精度≥11,排除自动填充1日的低精度数据
  FILTER(?birthdate wikibase:timePrecision >= 11)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel
ORDER BY DESC(?followers)
LIMIT 40

这样就能正确筛选出真实1月1日出生的人员数据,同时避免混入无效结果。

内容的提问来源于Stack Exchange,提问作者Travis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 07:16:02