query-e215bc8dd75931892c10b883c4438d52
Airports (again :), and with that query, you'll see that when there is multiples statements for same month+year : they are added instead of being sampled. I wonder if I change the (SUM(?numberperperiod) AS ?number) to (MAX(?numberperperiod) AS ?number) would have any drawbacks/side effects. (Q854130)Cape Town International Airport Hello, sorry to bother you again, hope you'll get a better year 2021 than 2020! I'm having a difficulty when airport data has multiples monthly source. Eg with ]reply[21:46, 8 January 2021 (UTC) 💛●✒️●💬 BouzinacAny thoughts ?
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?year ?item ?itemLabel (MAX(?number) AS ?passengers)
(SAMPLE(COALESCE(?reference_URL, ?monthly_reference_URL2)) AS ?sample_reference_URL)
WHERE
{
{
# Get the sum of monthly values within a year
SELECT ?item ?year (SUM(?numberperperiod) AS ?number) (SAMPLE(?monthly_reference_URL) AS ?monthly_reference_URL2)
WHERE
{
# Get a sample reference URL for each monthly value
{
SELECT ?item ?year ?numberperperiod (SAMPLE(?reference_URL) AS ?monthly_reference_URL)
WHERE
{
{
SELECT ?item ?statement ?year ?timevalue ?numberperperiod ?reference_URL
WHERE
{
?item wdt:P238 ?airport_code
VALUES ?airport_code
{
"CPT"
}
?item p:P3872 ?statement.
?statement pqv:P585 ?timevalue;
ps:P3872 ?numberperperiod.
?timevalue wikibase:timeValue ?date.
OPTIONAL { ?statement pq:P518 ?applies. }
OPTIONAL { ?statement prov:wasDerivedFrom / (pr:P854|pr:P4656) ?reference_URL. }
FILTER (BOUND(?applies)=false || ?applies = wd:Q2165236 )
MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
BIND (YEAR(?date) AS ?year)
FILTER (?year >1949).
FILTER (?year < YEAR(NOW()))
}
} ?timevalue wikibase:timePrecision ?prec.
FILTER (?prec > 9)
}
GROUP BY ?item ?statement ?year ?numberperperiod
# Include ?statement in the GROUP BY because ?numberperperiod may not be unique
}
}
GROUP BY ?item ?year
}
UNION
{
?timevalue wikibase:timePrecision 9 .
BIND (?numberperperiod AS ?number)
BIND (?reference_URL AS ?sample_reference_URL)
{
SELECT ?item ?statement ?year ?timevalue ?numberperperiod ?reference_URL
WHERE
{
?item wdt:P238 ?airport_code
VALUES ?airport_code
{
"CPT"
}
?item p:P3872 ?statement.
?statement pqv:P585 ?timevalue;
ps:P3872 ?numberperperiod.
?timevalue wikibase:timeValue ?date.
OPTIONAL { ?statement pq:P518 ?applies. }
OPTIONAL { ?statement prov:wasDerivedFrom / (pr:P854|pr:P4656) ?reference_URL. }
FILTER (BOUND(?applies)=false || ?applies = wd:Q2165236 )
MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
BIND (YEAR(?date) AS ?year)
FILTER (?year >1949).
FILTER (?year < YEAR(NOW()))
}
} }
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?item ?itemLabel ?year
ORDER BY ?item DESC (?year)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v15("?airport_code")
v4("?applies")
v9("?date")
v1("?item"):::projected
v11("?monthly_reference_URL")
v13("?monthly_reference_URL2"):::projected
v14("?number"):::projected
v8("?numberperperiod")
v15("?passengers")
v3("?prec")
v10("?reference_URL"):::projected
v16("?sample_reference_URL")
v6("?statement")
v7("?timevalue")
v15("?year"):::projected
a1((" "))
a2((" "))
c15(["wikibase:DeprecatedRank"]):::iri
c20(["fr"]):::literal
c18(["bd:serviceParam"]):::iri
c1(["9^^xsd:integer"]):::literal
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v7 --"wikibase:timePrecision"--> c1
bind0[/"?numberperperiod"/]
v8 --o bind0
bind0 --as--o v14
bind1[/"?reference_URL"/]
v10 --o bind1
bind1 --as--o v16
f2[["?year < year-from-dateTime(NOW())"]]
f2 --> v15
f3[["?year > '1949^^xsd:integer'"]]
f3 --> v15
f4[["(bound(?applies) = 'false^^xsd:boolean' || ?applies = 'wd:Q2165236')"]]
f4 --> v4
v1 --"p:direct/P238"--> v15
bind5[/VALUES ?airport_code/]
bind5-->v15
bind50(["CPT"])
bind50 --> bind5
v1 --"p:P3872"--> v6
v6 --"p:qualifier/value/P585"--> v7
v6 --"p:statement/P3872"--> v8
v7 --"wikibase:timeValue"--> v9
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P518".-> v4
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v6 -."prov:wasDerivedFrom".-> a2
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
a2 --"p:reference/P4656"--> v10
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
a2 --"p:reference/P854"--> v10
end
union1r <== or ==> union1l
end
end
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v6 --"wikibase:rank"--> c15
end
bind7[/"year-from-dateTime(?date)"/]
v9 --o bind7
bind7 --as--o v15
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f8[["?prec > '9^^xsd:integer'"]]
f8 --> v3
f9[["?year < year-from-dateTime(NOW())"]]
f9 --> v15
f10[["?year > '1949^^xsd:integer'"]]
f10 --> v15
f11[["(bound(?applies) = 'false^^xsd:boolean' || ?applies = 'wd:Q2165236')"]]
f11 --> v4
v1 --"p:direct/P238"--> v15
bind12[/VALUES ?airport_code/]
bind12-->v15
bind120(["CPT"])
bind120 --> bind12
v1 --"p:P3872"--> v6
v6 --"p:qualifier/value/P585"--> v7
v6 --"p:statement/P3872"--> v8
v7 --"wikibase:timeValue"--> v9
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P518".-> v4
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v6 -."prov:wasDerivedFrom".-> a1
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
a1 --"p:reference/P4656"--> v10
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
a1 --"p:reference/P854"--> v10
end
union2r <== or ==> union2l
end
end
subgraph minus13["MINUS"]
style minus13 stroke-width:6px,fill:pink,stroke:red;
v6 --"wikibase:rank"--> c15
end
bind14[/"year-from-dateTime(?date)"/]
v9 --o bind14
bind14 --as--o v15
v7 --"wikibase:timePrecision"--> v3
bind16[/"sample(?reference_URL)"/]
v10 --o bind16
bind16 --as--o v11
bind19[/"sum(?numberperperiod)"/]
v8 --o bind19
bind19 --as--o v14
bind20[/"sample(?monthly_reference_URL)"/]
v11 --o bind20
bind20 --as--o v13
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c18 --"wikibase:language"--> c20
end
bind23[/"max(?number)"/]
v14 --o bind23
bind23 --as--o v15
bind24[/"sample(?reference_URL?monthly_reference_URL2)"/]
v10 --o bind24
v13 --o bind24
bind24 --as--o v16