Project:SPARQL/admin: Difference between revisions

m
no edit summary
mNo edit summary
Line 723: Line 723:
order by ?personLabel ?positionLabel
order by ?personLabel ?positionLabel
</sparql>
</sparql>
== Wikidata ==
=== Places that link to wikidata AND have wikidata P625 geo coordinates ===
<sparql tryit="1">
#title:wikidata geo coords P625
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 distinct ?locationLabel ?location ?wikidata ?wd_geo # ?bn_geo
WHERE { 
 
  {?item bnwdt:P29  ?location . } # resided at
  union
  {?location bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
  union
  {?item bnwdt:P2  ?location . } # OR location P2
  # any other possibles ?  "P33 but only if i/o arch site or historic house" historic house Q2961  arch site Q86
  union
  {?item bnwdt:P33 ?location .} # admin territory ADDS ONE ROW. lol.
   
      ?location bnwdt:P117 ?ws .  # wikidata id       
       
        bind(iri(concat("http://www.wikidata.org/entity/", str(?ws))) as ?wikidata) .
        SERVICE <https://query.wikidata.org/sparql> {
            ?wikidata wdt:P625 ?wd_geo .  # does the wikidata page have geocoords?
        } # /wikidata service 
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata ?locationLabel
</sparql>
=== Locations that don't have Wikidata links or their Wikidata pages lack geocoordinates===
<sparql tryit="1">
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 distinct ?locationLabel ?location ?wikidata ?wd_geo ?instanceLabel ?bn_geo
WHERE { 
 
  {?item bnwdt:P29  ?location . } # resided at
  union
  {?location bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
  union
  {?item bnwdt:P2  ?location . } # OR location P2
  # any other possibles ?
 
  optional { ?location bnwdt:P12 ?instance .  } # check instance of
 
  optional {   
      ?location bnwdt:P117 ?ws .  # wikidata id       
       
        bind(iri(concat("http://www.wikidata.org/entity/", str(?ws))) as ?wikidata) .
        SERVICE <https://query.wikidata.org/sparql> {
          optional {?wikidata wdt:P625 ?wd_geo .}  # does the wikidata page have geocoords?
        } # /wikidata service 
    } #/wikidata optional
 
  filter (!bound(?wd_geo) ). # no geocoords in wikidata. some may have coords in BN...
 
  optional { ?location bnwdt:P153 ?bn_geo .  } # so check for coords in BN
  ##filter (!bound(?bn_geo)) . # uncomment to filter those out as well
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata ?locationLabel
</sparql>
===All places (by coordinate location on wikidata), filtering out places already listed as instance of locality===
<sparql tryit="1">
# All places (by coordinate location on wikidata), filtering out places already listed as instance of locality
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/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX prov: <http://www.w3.org/ns/prov#>
SELECT ?place ?placeLabel ?WDitem ?WDcoordinate_location
WHERE { 
  ?place bnwdt:P33 ?admin_area .  #select items with 'located in the administrative territorial entity' statements
  ?place bnwdt:P117 ?Qnumber .    #get wikidata ID
  FILTER NOT EXISTS {?place bnwdt:P12 bnwd:Q2147 .}      #filter out places already listed as instance of locality
 
  #create reference to Wikibase entity
  BIND(IRI(concat("http://www.wikidata.org/entity/", ?Qnumber)) as ?WDitem )
  #on Wikibase do
  SERVICE <https://query.wikidata.org/sparql> {
        ?WDitem wdt:P625 ?WDcoordinate_location . #get coordinate location on wikidata
      }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?place ?placeLabel ?WDitem ?WDcoordinate_location
ORDER BY ?placeLabel
</sparql>
=== Wikidata ID is a URL ===
<sparql tryit="1">
#title:check for accidental use of URL instead of wikidata ID
## all checked and fixed at 18/12/23 but adding the query in case it recurs
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 distinct ?item ?itemLabel ?wd_http
WHERE { 
 
  ?item bnwdt:P117 ?wd_http .  # wikidata id       
 
  filter(strstarts(str(?wd_http), "http")).
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?itemLabel
</sparql>
=== Wikidata URL is not a URL ===
<sparql tryit="1">
#title:check for wikidata URLs that don't start with http. could still be other problems!
## all checked and fixed at 18/12/23 but adding the query in case of any recurring issues
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 distinct ?item ?itemLabel ?wd_url
WHERE { 
 
  ?item bnp:P117 ?ws .  # wikidata id       
    ?ws bnpq:P14 ?wd_url .
  filter(!strstarts(str(?wd_url), "http")).
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?itemLabel
</sparql>


== Reference queries ==
== Reference queries ==
Line 1,082: Line 1,266:
}
}
order by ?item
order by ?item
</sparql>
== Wikidata ==
=== Places that link to wikidata AND have wikidata P625 geo coordinates ===
<sparql tryit="1">
#title:wikidata geo coords P625
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 distinct ?locationLabel ?location ?wikidata ?wd_geo # ?bn_geo
WHERE { 
 
  {?item bnwdt:P29  ?location . } # resided at
  union
  {?location bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
  union
  {?item bnwdt:P2  ?location . } # OR location P2
  # any other possibles ?  "P33 but only if i/o arch site or historic house" historic house Q2961  arch site Q86
  union
  {?item bnwdt:P33 ?location .} # admin territory ADDS ONE ROW. lol.
   
      ?location bnwdt:P117 ?ws .  # wikidata id       
       
        bind(iri(concat("http://www.wikidata.org/entity/", str(?ws))) as ?wikidata) .
        SERVICE <https://query.wikidata.org/sparql> {
            ?wikidata wdt:P625 ?wd_geo .  # does the wikidata page have geocoords?
        } # /wikidata service 
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata ?locationLabel
</sparql>
=== Locations that don't have Wikidata links or their Wikidata pages lack geocoordinates===
<sparql tryit="1">
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 distinct ?locationLabel ?location ?wikidata ?wd_geo ?instanceLabel ?bn_geo
WHERE { 
 
  {?item bnwdt:P29  ?location . } # resided at
  union
  {?location bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
  union
  {?item bnwdt:P2  ?location . } # OR location P2
  # any other possibles ?
 
  optional { ?location bnwdt:P12 ?instance .  } # check instance of
 
  optional {   
      ?location bnwdt:P117 ?ws .  # wikidata id       
       
        bind(iri(concat("http://www.wikidata.org/entity/", str(?ws))) as ?wikidata) .
        SERVICE <https://query.wikidata.org/sparql> {
          optional {?wikidata wdt:P625 ?wd_geo .}  # does the wikidata page have geocoords?
        } # /wikidata service 
    } #/wikidata optional
 
  filter (!bound(?wd_geo) ). # no geocoords in wikidata. some may have coords in BN...
 
  optional { ?location bnwdt:P153 ?bn_geo .  } # so check for coords in BN
  ##filter (!bound(?bn_geo)) . # uncomment to filter those out as well
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata ?locationLabel
</sparql>
===All places (by coordinate location on wikidata), filtering out places already listed as instance of locality===
<sparql tryit="1">
# All places (by coordinate location on wikidata), filtering out places already listed as instance of locality
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/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX prov: <http://www.w3.org/ns/prov#>
SELECT ?place ?placeLabel ?WDitem ?WDcoordinate_location
WHERE { 
  ?place bnwdt:P33 ?admin_area .  #select items with 'located in the administrative territorial entity' statements
  ?place bnwdt:P117 ?Qnumber .    #get wikidata ID
  FILTER NOT EXISTS {?place bnwdt:P12 bnwd:Q2147 .}      #filter out places already listed as instance of locality
 
  #create reference to Wikibase entity
  BIND(IRI(concat("http://www.wikidata.org/entity/", ?Qnumber)) as ?WDitem )
  #on Wikibase do
  SERVICE <https://query.wikidata.org/sparql> {
        ?WDitem wdt:P625 ?WDcoordinate_location . #get coordinate location on wikidata
      }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
GROUP BY ?place ?placeLabel ?WDitem ?WDcoordinate_location
ORDER BY ?placeLabel
</sparql>
=== Wikidata ID is a URL ===
<sparql tryit="1">
#title:check for accidental use of URL instead of wikidata ID
## all checked and fixed at 18/12/23 but adding the query in case it recurs
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 distinct ?item ?itemLabel ?wd_http
WHERE { 
 
  ?item bnwdt:P117 ?wd_http .  # wikidata id       
 
  filter(strstarts(str(?wd_http), "http")).
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?itemLabel
</sparql>
=== Wikidata URL is not a URL ===
<sparql tryit="1">
#title:check for wikidata URLs that don't start with http. could still be other problems!
## all checked and fixed at 18/12/23 but adding the query in case of any recurring issues
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 distinct ?item ?itemLabel ?wd_url
WHERE { 
 
  ?item bnp:P117 ?ws .  # wikidata id       
    ?ws bnpq:P14 ?wd_url .
  filter(!strstarts(str(?wd_url), "http")).
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?itemLabel
</sparql>
</sparql>
582

edits