Template:ValidAtDate
This model is a Partial query. This means it can be used to help writing SPARQL query. to find the values of a certain property at a certain time.
Variable naming
edit- TBD (the template variables should be reworked, it’s a mess)
Usage
edit- Chief of states in the world in 1960
{{sparql link|label=Chief of states in 1960|title=Chief of states in 1960
|query=
select ?country ?countryLabel ?chief_of_state ?chief_of_stateLabel {
{{ValidAtDate|?country|instance of|Q3624078|beginTime=1960}} # sovereign state in 1960
{{ValidAtDate|?country|P6|?chief_of_state|beginTime=1960}} # sovereign state in 1960
{{query intl}} # query service
}
}}
Chief of states in 1960 (query)
{{ValidAtDate|?item|P131|?value|beginTime=01-01-2000}}
Full example
{{sparql|query=select ?ville
{
# french municipalities, in year 2000
{{validAtDate|?ville|P31|Q484170|beginTime=2000-01-01}}
# in the calvados department, in 2000
{{validAtDate|?ville|P131|Q3249|beginTime=2000-01-01}}
}}
}}
select ?ville
{
# french municipalities, in year 2000
##### ?ville : P31 Valid in [ 2000-01-01, ] #####
bind ("2000-01-01"^^xsd:dateTime as ?beginTimevilleP31) # bounds
bind ("2000-01-01"^^xsd:dateTime as ?endTimevilleP31)
# get statements for our property P31
?ville p:P31 ?statementvilleP31 .
?statementvilleP31
wikibase:rank ?rank_P31 ; # filter out deprecated statements
ps:P31 wd:Q484170 . # main value of the P31 statement
optional {
?statementvilleP31
pq:P580 ?beginStatementvilleP31 . # begin statement validity date
}
optional {
?statementvilleP31
pq:P582 ?endStatementvilleP31 . # end statement validity date
}
# in case the statement has no "end time", just use "now" as a date
bind(coalesce(?endStatementvilleP31, now()) as ?endStatementvilleP31Final) .
# in case it has no begin time, use arbitrarily year 1
bind(coalesce(?beginStatementvilleP31, "0001-01-01"^^xsd:dateTime) as ?beginStatementvilleP31Final) .
filter (?rank_P31 != wikibase:DeprecatedRank) . # filter out deprecated ranks
# only get statements valids in the wanted time period
filter (?endStatementvilleP31Final >= ?beginTimevilleP31 && ?beginStatementvilleP31Final <= ?endTimevilleP31 )
#### / ?ville : P31 Valid in [ 2000-01-01, ]
# in the calvados department, in 2000
##### ?ville : P131 Valid in [ 2000-01-01, ] #####
bind ("2000-01-01"^^xsd:dateTime as ?beginTimevilleP131) # bounds
bind ("2000-01-01"^^xsd:dateTime as ?endTimevilleP131)
# get statements for our property P131
?ville p:P131 ?statementvilleP131 .
?statementvilleP131
wikibase:rank ?rank_P131 ; # filter out deprecated statements
ps:P131 wd:Q3249 . # main value of the P131 statement
optional {
?statementvilleP131
pq:P580 ?beginStatementvilleP131 . # begin statement validity date
}
optional {
?statementvilleP131
pq:P582 ?endStatementvilleP131 . # end statement validity date
}
# in case the statement has no "end time", just use "now" as a date
bind(coalesce(?endStatementvilleP131, now()) as ?endStatementvilleP131Final) .
# in case it has no begin time, use arbitrarily year 1
bind(coalesce(?beginStatementvilleP131, "0001-01-01"^^xsd:dateTime) as ?beginStatementvilleP131Final) .
filter (?rank_P131 != wikibase:DeprecatedRank) . # filter out deprecated ranks
# only get statements valids in the wanted time period
filter (?endStatementvilleP131Final >= ?beginTimevilleP131 && ?beginStatementvilleP131Final <= ?endTimevilleP131 )
#### / ?ville : P131 Valid in [ 2000-01-01, ]
}
See also
editHelper template to help select statement true at a certain point or interval of time. Useful for usecase such as « who was president at year 1900 » or « who were the presidents of the 1900-1930 period ».
Parameter | Description | Type | Status | |
---|---|---|---|---|
subject | 1 | no description | Unknown | optional |
property | 2 | no description | Unknown | optional |
value | 3 | no description | Unknown | optional |
beginTime | beginTime | Begin date of the period we want the statement to be valid in. If « endTime » is omitted, only statements valid at this point in time will be included | Unknown | optional |
endTime | endTime | no description | Unknown | optional |
The above documentation is transcluded from Template:ValidAtDate/doc (edit | history). Editors can experiment in this template's sandbox (create | mirror) and testcases (create) page. Please add categories to the /doc subpage. Subpages of this template. |