query-8522df0febdf0c5049fd8e0967e227ed

rq turtle/ttl

Propertiesinstance of (P31)subclass of (P279)inception (P571)dissolved, abolished or demolished date (P576)

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#>
SELECT DISTINCT ?event ?eventLabel ?date
WHERE
{
    # find admin territories of Germany
    ?event wdt:P31/wdt:P279* wd:Q387917.
        # with founding/inception date
    #OPTIONAL { ?event wdt:P571 ?date. }
        # abolished date
    OPTIONAL { ?event wdt:P576 ?date. }
    # but at least one of those
    FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
    # calculate age (days, negative are in the future)
    BIND(NOW() - ?date AS ?age).
    FILTER(0 <= ?age && ?age < 365).
    # and get a label as well
    SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
} ORDER BY ( ?eventLabel )
# limit to 100 results so we don't timeout
LIMIT 100

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?age") v3("?date"):::projected v4("?event"):::projected v1("?eventLabel"):::projected a1((" ")) c6(["wd:Q387917"]):::iri c11(["de"]):::literal c9(["bd:serviceParam"]):::iri f0[["'0^^xsd:integer' <= ?age?age < '365^^xsd:integer'"]] f0 --> v5 f1[["bound(?date)?date = 'xsd:dateTime'"]] f1 --> v3 v4 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P576".-> v3 end bind2[/"NOW() - ?date"/] v3 --o bind2 bind2 --as--o v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end