query-4b961e89b4cbe5f1e11dd91d91be7f45

rq turtle/ttl

UK Politicians born on Friday the 13th SELECT ?item ?itemLabel ?dob WHERE { ?item wdt:P31 wd:Q5. ?item wdt:P27 wd:Q145. ?item wdt:P106 wd:Q82955. ?item wdt:P569 ?dob.

day of week algorithm from https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Disparate_variation

BIND(YEAR(?dob) AS ?year) BIND(MONTH(?dob) AS ?month) BIND(DAY(?dob) AS ?day) BIND(FLOOR(?year / 100) AS ?century) BIND(REPLACE( STR(?year), "^..", "") AS ?yy) BIND( IF (?month <= 2, xsd:integer(?yy) - 1, xsd:integer(?yy)) AS ?yyx) BIND( IF (?month <= 2, ?month + 10, ?month - 2) AS ?mm) BIND( ?day + FLOOR(2.6 * ?mm - 0.2) + ?yyx + FLOOR(?yyx / 4) + FLOOR(?century / 4) - 2 * ?century AS ?a) BIND( ?a - FLOOR(?a / 7) * 7 AS ?mod7) # mod7: 0 = Sunday... 6 = Saturday FILTER(?day = 13 && ?mod7 = 5) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# UK Politicians born on Friday the 13th
SELECT ?item ?itemLabel ?dob WHERE {
 ?item wdt:P31 wd:Q5.
 ?item wdt:P27 wd:Q145.
 ?item wdt:P106 wd:Q82955.
 ?item wdt:P569 ?dob.
# day of week algorithm from https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Disparate_variation
 BIND(YEAR(?dob) AS ?year)
 BIND(MONTH(?dob) AS ?month)
 BIND(DAY(?dob) AS ?day)
 BIND(FLOOR(?year / 100) AS ?century)
 BIND(REPLACE( STR(?year), "^..", "") AS ?yy)
 BIND( IF (?month <= 2, xsd:integer(?yy) - 1, xsd:integer(?yy)) AS ?yyx)
 BIND( IF (?month <= 2, ?month + 10, ?month - 2) AS ?mm)
 BIND( ?day + FLOOR(2.6 * ?mm - 0.2) + ?yyx + FLOOR(?yyx / 4) + FLOOR(?century / 4) - 2 * ?century AS ?a)
 BIND( ?a - FLOOR(?a / 7) * 7 AS ?mod7)
 # mod7: 0 = Sunday... 6 = Saturday
 FILTER(?day = 13 && ?mod7 = 5)
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v11("?a") v7("?century") v7("?day") v4("?dob"):::projected v3("?item"):::projected v10("?mm") v12("?mod7") v6("?month") v5("?year") v8("?yy") v9("?yyx") c8(["wd:Q82955"]):::iri c11(["bd:serviceParam"]):::iri c4(["wd:Q5"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal c6(["wd:Q145"]):::iri f0[["?day = '13^^xsd:integer'?mod7 = '5^^xsd:integer'"]] f0 --> v7 f0 --> v12 v3 --"wdt:P31"--> c4 v3 --"wdt:P27"--> c6 v3 --"wdt:P106"--> c8 v3 --"wdt:P569"--> v4 bind1[/"year-from-dateTime(?dob)"/] v4 --o bind1 bind1 --as--o v5 bind2[/"month-from-dateTime(?dob)"/] v4 --o bind2 bind2 --as--o v6 bind3[/"day-from-dateTime(?dob)"/] v4 --o bind3 bind3 --as--o v7 bind4[/"numeric-floor(?year / '100^^xsd:integer')"/] v5 --o bind4 bind4 --as--o v7 bind5[/"replace(str(?year),'^..','')"/] v5 --o bind5 bind5 --as--o v8 bind6[/"if(?month <= '2^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(?yy) - '1^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(?yy))"/] v6 --o bind6 v8 --o bind6 bind6 --as--o v9 bind7[/"if(?month <= '2^^xsd:integer',?month + '10^^xsd:integer',?month - '2^^xsd:integer')"/] v6 --o bind7 bind7 --as--o v10 bind8[/"?day + numeric-floor('2.6^^xsd:decimal' * ?mm - '0.2^^xsd:decimal') + ?yyx + numeric-floor(?yyx / '4^^xsd:integer') + numeric-floor(?century / '4^^xsd:integer') - '2^^xsd:integer' * ?century"/] v7 --o bind8 v10 --o bind8 v9 --o bind8 v7 --o bind8 bind8 --as--o v11 bind9[/"?a - numeric-floor(?a / '7^^xsd:integer') * '7^^xsd:integer'"/] v11 --o bind9 bind9 --as--o v12 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end