Project:SPARQL/examples: Difference between revisions

Line 319: Line 319:
} group by ?person ?personLabel ?statements order by desc(?residence_count)
} group by ?person ?personLabel ?statements order by desc(?residence_count)
# Credit to @Tagishsimon for helping me figure out the counting logic here
# Credit to @Tagishsimon for helping me figure out the counting logic here
</sparql>
===Places at which women resided, sorted by how many residences all women had at a given village/town/city/London area===
<sparql tryit="1">
# Places at which women resided, sorted by how many residences all women had at a given village/town/city/London area
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT ?residence ?residenceLabel (count(?residence) as ?residence_count) #count number of places at which women lived
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . # select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
  ?person bnwdt:P29 ?residence . # select residences
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?residence ?residenceLabel
ORDER BY DESC(?residence_count)
</sparql>
<sparql tryit="1">
# Districts in which women resided, sorted by how many residences all women had in that district (or equivalent sub-level for non-UK residences)
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT ?district ?districtLabel (count(?district) as ?district_count) #count number of districts in which women lived
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . # select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
  ?person bnwdt:P29 ?residence . # select residences
  ?residence bnwdt:P33 ?district . #select districts
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?district ?districtLabel
ORDER BY DESC(?district_count)
</sparql>
<sparql tryit="1">
# Counties in which women resided, sorted by how many residences all women had in that county
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT ?county ?countyLabel (count(?county) as ?county_count) #count number of counties in which women lived
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . # select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
  ?person bnwdt:P29 ?residence . # select residences
  ?residence bnwdt:P33 ?district . #select districts
  ?district bnwdt:P33 ?county . #select counties
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?county ?countyLabel
ORDER BY DESC(?county_count)
</sparql>
<sparql tryit="1">
# Regions in which women resided, sorted by how many residences all women had in that region
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT ?region ?regionLabel (count(?region) as ?region_count) #count number of regions in which women lived
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . # select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
  ?person bnwdt:P29 ?residence . # select residences
  ?residence bnwdt:P33 ?district . #select districts
  ?district bnwdt:P33 ?county . #select counties
  ?county bnwdt:P33 ?region . #select region
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?region ?regionLabel
ORDER BY DESC(?region_count)
</sparql>
</sparql>