User:MartinPoulter/queries/calendars

From Wikidata
Jump to navigation Jump to search

Calendar ordering of dates[edit]

SELECT ?month_ordinal ?monthLabel ?day_ordinal WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal.
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ]
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY xsd:integer(?month_ordinal) xsd:integer(?day_ordinal)
Try it!

Calendar of birthdays of women who studied at Oxford[edit]

SELECT ?monthLabel (?day_int as ?d) ?personLabel ?personDesc
   (URI(CONCAT("https://tools.wmflabs.org/reasonator/?q=", STRAFTER(STR(?rperson),"entity/") )) as ?link) WHERE {
{ SELECT ?month_int ?month ?day_int (SAMPLE(?person) AS ?rperson) WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal. # These lines generate a calendar from January 1 to December 31
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
 BIND(xsd:integer(?month_ordinal) AS ?month_int)
 BIND(xsd:integer(?day_ordinal) AS ?day_int)
OPTIONAL {
# Define the people we're interested in
{?person wdt:P69 wd:Q34433 } UNION {?person wdt:P69/wdt:P31 wd:Q2581649 } # educated at Oxford or an Oxford college
?person wdt:P21 wd:Q6581072 ; # female
   p:P569/psv:P569 ?date_node. # birth date
?date_node wikibase:timePrecision "11"^^xsd:integer ; # birth date has specific day
   wikibase:timeValue ?birthdate .        
filter(DAY(?birthdate)=?day_int) filter (MONTH(?birthdate)=?month_int )
}
} GROUP BY ?month_int ?month ?day_int }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?rperson rdfs:label ?personLabel. ?rperson schema:description ?personDesc. ?month rdfs:label ?monthLabel }
} ORDER BY ?month_int ?day_int
Try it!

Calendar of birthdays of suffragists[edit]

SELECT ?monthLabel (?day_int as ?d) ?personLabel ?personDesc
   (URI(CONCAT("https://tools.wmflabs.org/reasonator/?q=", SUBSTR(STR(?rperson),32) )) as ?link) WHERE {
{ SELECT ?month_int ?month ?day_int (SAMPLE(?person) AS ?rperson) WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal. # These lines generate a calendar from January 1 to December 31
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
 BIND(xsd:integer(?month_ordinal) AS ?month_int)
 BIND(xsd:integer(?day_ordinal) AS ?day_int)
OPTIONAL {
# Define the people we're interested in
{?person wdt:P106 wd:Q27532437 } UNION {?person wdt:P106 wd:Q322170 } # suffragette or suffragist
?person p:P569/psv:P569 ?date_node. # birth date
?date_node wikibase:timePrecision "11"^^xsd:integer ; # birth date has specific day
   wikibase:timeValue ?birthdate .        
filter(DAY(?birthdate)=?day_int) filter (MONTH(?birthdate)=?month_int )
}
} GROUP BY ?month_int ?month ?day_int }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?rperson rdfs:label ?personLabel. ?rperson schema:description ?personDesc. ?month rdfs:label ?monthLabel }
} ORDER BY ?month_int ?day_int
Try it!

Calendar of World __ days[edit]

Suggested by Andy Mabbett

#title:Calendar of Awareness days 
SELECT DISTINCT ?month_int ?monthLabel (?day_int as ?d) ?world_dayLabel (?world_day as ?link) (GROUP_CONCAT(DISTINCT ?countryLabel; separator=", ") as ?countries) WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal.
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
 BIND(xsd:integer(?month_ordinal) AS ?month_int)
 BIND(xsd:integer(?day_ordinal) AS ?day_int)
  
VALUES ?type {wd:Q2558684 wd:Q422695} # World ___ day; Awareness day 
?world_day wdt:P31 ?type; wdt:P837 ?day
OPTIONAL {?world_day wdt:P17 ?country}
  
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
      ?month rdfs:label ?monthLabel. ?world_day rdfs:label ?world_dayLabel. ?country rdfs:label ?countryLabel }
} GROUP BY ?month_int ?monthLabel ?day_int ?world_dayLabel ?world_day
ORDER BY ?month_int ?d
Calendar of Awareness days

Calendar of saints' feast days[edit]

SELECT DISTINCT ?monthLabel (?day_int as ?d) ?saintLabel (URI(CONCAT("https://tools.wmflabs.org/reasonator/?q=", SUBSTR(STR(?saint),32) )) as ?link) WHERE {
{ SELECT ?month_int ?month ?day_int ?saint WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal.
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
 BIND(xsd:integer(?month_ordinal) AS ?month_int)
 BIND(xsd:integer(?day_ordinal) AS ?day_int)
?saint wdt:P841 ?day # saint's feast day
}  }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
} ORDER BY ?month_int ?d ?saintLabel
Try it!

Count of saint's feast days per date[edit]

#defaultView:BarChart
SELECT (CONCAT(STR(?monthLabel), " ", STR(?day_int)) AS ?calendar) (COUNT(?saint) AS ?count) ?month_int ?day_int WHERE {
{ SELECT ?month_int ?month ?day_int ?saint WHERE {
?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal.
?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
 BIND(xsd:integer(?month_ordinal) AS ?month_int)
 BIND(xsd:integer(?day_ordinal) AS ?day_int)
?saint wdt:P841 ?day # saint's feast day
}  }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?month rdfs:label ?monthLabel }
} GROUP BY ?month_int ?monthLabel ?day_int
ORDER BY ?month_int ?day_int
Try it!

Revised version of nuclear power plant construction query[edit]

The following query uses these:

  • Properties: instance of (P31)  View with Reasonator View with SQID, followed by (P156)  View with Reasonator View with SQID, point in time (P585)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, inception (P571)  View with Reasonator View with SQID, country (P17)  View with Reasonator View with SQID
    #defaultView:BarChart
    SELECT ?yearLabel (COUNT(?country) AS ?count) (SAMPLE(?cLabel) AS ?cLabel) WHERE {
      ?year wdt:P31 wd:Q577;
        wdt:P156/wdt:P585 ?next_year_point;
        wdt:P585 ?year_point.
      FILTER("1950-01-01"^^xsd:dateTime <= ?year_point && ?year_point < "2000-01-01"^^xsd:dateTime).
      OPTIONAL { ?object (wdt:P31/wdt:P279*) wd:Q134447.
      ?object wdt:P571 ?_inception.
      ?object wdt:P17 ?country.
      ?country rdfs:label ?countryLabel. FILTER((LANG(?countryLabel)) = "en")
      FILTER(?year_point <= ?_inception && ?_inception < ?next_year_point)
      }
      BIND(IF(BOUND(?country),?countryLabel,"none") AS ?cLabel)
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
    } GROUP BY ?yearLabel ?country
    ORDER BY ?yearLabel