如何从维基数据中找到夏天出生的人?

时间:2017-01-25 01:31:19

标签: sparql wikidata wikidata-api

我的目标是通过夏天出生的维基数据找人。对1983年有用的是:

FILTER((?birth > "1983-06-20"^^xsd:dateTime) && (?birth < "1983-10-31"^^xsd:dateTime))
  1. 但我希望它每年过滤一次,即不仅仅是1983年。我该怎么做 换线?
  2. 如果我想增加一年,例如1983年到2000年,我该怎么做?

1 个答案:

答案 0 :(得分:4)

为了让人们在 6月20日之后<10月31日之前出生,您可以使用以下两种变体之一:

SELECT ?item ?birth WHERE {
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P569 ?birth .

  # variant 1: get from 20.06 to 30.06 and from 01.07 to 31.10
  FILTER(
    (month(?birth) = 6 && day(?birth) > 19) || 
    (month(?birth) > 6 && month(?birth) < 11)
  )

  # variant 2: get from 01.06 to 31.10 and remove from 01.06 to 19.06
  FILTER(month(?birth) > 5 && month(?birth) < 11)
  FILTER(!(month(?birth) = 6 && day(?birth) < 20))

} LIMIT 1000

如果你还要添加年度跨度(1983 - 2000年),请将这两个过滤器包括在其他过滤器之前:

FILTER (?birth >= "1983-01-01"^^xsd:dateTime)
FILTER (?birth <= "2000-12-31"^^xsd:dateTime)
相关问题