query-e836649bacaac02a9f815614044cd547
11:07, 14 February 2020 (UTC)) talk (Dipsacus fullonum --Somehow ordering is by count rather than year. It worked out better in my second query above, but that had data for every year.: Then just fill the holes with 0 values:Jura1@ 12:25, 14 February 2020 (UTC) JuraIdeally, it would be by decade without holes. ---
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
#defaultView:LineChart
SELECT (STR(?decade_number) AS ?decade) (MAX(?count) AS ?ct)
WHERE
{
{
{
SELECT ?decade_number (COUNT(DISTINCT ?item) as ?count)
WHERE
{
?item wdt:P735 wd:Q2829505 ; wdt:P569 ?b .
?item p:P569/psv:P569 [ wikibase:timeValue ?b ; wikibase:timePrecision ?precision ]
FILTER(?precision > 7 )
BIND( (FLOOR(YEAR(?b)/10)*10) as ?decade_number)
}
GROUP BY ?decade_number
ORDER BY ?decade_number
} }
UNION
{
{
SELECT (MIN(?decade_number) AS ?first_decade) (MAX(?decade_number) AS ?last_decade)
WHERE
{
{
SELECT ?decade_number (COUNT(DISTINCT ?item) as ?count)
WHERE
{
?item wdt:P735 wd:Q2829505 ; wdt:P569 ?b .
?item p:P569/psv:P569 [ wikibase:timeValue ?b ; wikibase:timePrecision ?precision ]
FILTER(?precision > 7 )
BIND( (FLOOR(YEAR(?b)/10)*10) as ?decade_number)
}
GROUP BY ?decade_number
ORDER BY ?decade_number
} }
}
?decade_item wdt:P31 wd:Q39911.
?decade_item wdt:P585 ?decade_time.
BIND( (FLOOR(YEAR(?decade_time)/10)*10) as ?decade_number)
FILTER (?decade_number > ?first_decade && ?decade_number < ?last_decade)
VALUES ?count { 0 }
}
}
GROUP BY ?decade_number
ORDER BY ?decade_number
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?b")
v10("?count"):::projected
v11("?ct")
v10("?decade")
v8("?decade_item")
v10("?decade_number"):::projected
v9("?decade_time")
v8("?first_decade")
v3("?item")
v8("?last_decade")
v2("?precision")
a2((" "))
a1((" "))
a4((" "))
a3((" "))
c3(["wd:Q2829505"]):::iri
c10(["wd:Q39911"]):::iri
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
f0[["?decade_number > ?first_decade?decade_number < ?last_decade"]]
f0 --> v10
f0 --> v8
f0 --> v8
f1[["?precision > '7^^xsd:integer'"]]
f1 --> v2
v3 --"p:direct/P735"--> c3
v3 --"p:direct/P569"--> v4
a3 --"wikibase:timeValue"--> v4
a3 --"wikibase:timePrecision"--> v2
v3 --"p:P569"--> a4
a4 --"p:statement/value/P569"--> a3
bind2[/"numeric-floor(year-from-dateTime(?b) / '10^^xsd:integer') * '10^^xsd:integer'"/]
v4 --o bind2
bind2 --as--o v10
bind4[/"count(?item)"/]
v3 --o bind4
bind4 --as--o v10
bind7[/"min(?decade_number)"/]
v10 --o bind7
bind7 --as--o v8
bind8[/"max(?decade_number)"/]
v10 --o bind8
bind8 --as--o v8
v8 --"p:direct/P31"--> c10
v8 --"p:direct/P585"--> v9
bind9[/"numeric-floor(year-from-dateTime(?decade_time) / '10^^xsd:integer') * '10^^xsd:integer'"/]
v9 --o bind9
bind9 --as--o v10
bind10[/VALUES ?count/]
bind10-->v10
bind100(["0^^xsd:integer"])
bind100 --> bind10
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f11[["?precision > '7^^xsd:integer'"]]
f11 --> v2
v3 --"p:direct/P735"--> c3
v3 --"p:direct/P569"--> v4
a1 --"wikibase:timeValue"--> v4
a1 --"wikibase:timePrecision"--> v2
v3 --"p:P569"--> a2
a2 --"p:statement/value/P569"--> a1
bind12[/"numeric-floor(year-from-dateTime(?b) / '10^^xsd:integer') * '10^^xsd:integer'"/]
v4 --o bind12
bind12 --as--o v10
bind14[/"count(?item)"/]
v3 --o bind14
bind14 --as--o v10
end
union0r <== or ==> union0l
end
bind16[/"str(?decade_number)"/]
v10 --o bind16
bind16 --as--o v10
bind17[/"max(?count)"/]
v10 --o bind17
bind17 --as--o v11