Project:SPARQL/admin: Difference between revisions

(One intermediate revision by the same user not shown)
Line 194: Line 194:


</sparql>
</sparql>
=== Date of latest edit for every item, according to WQS ===
<sparql tryit="1">
#title:latest edits dates for wikibase items
## because of WQS disappearing data bugs this may not always match the latest edit in the page history
SELECT ?item ?date ?dateLabel
WHERE {
  ?item wikibase:timestamp ?date .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?date
</sparql>
=== Questions ===
<sparql tryit="1">
#title:asking questions
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 bnpsv: <https://beyond-notability.wikibase.cloud/prop/statement/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
SELECT ?personLabel ?propLabel ?link ?question
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 .
 
  ?person ?p ?s .
      ?prop wikibase:claim ?p;     
        wikibase:statementProperty ?ps.     
         
  # direct link to relevant part of page
        BIND (REPLACE(STR(?prop), "^.*/([^/]*)$", "$1") as ?pid).
        bind(iri(concat(str(?person), "#", ?pid)) as ?link ) .
 
  # the question
    ?s bnpq:P157 ?question . 
       
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?personLabel
</sparql>
== Place ==




Line 254: Line 321:




 
=== Reviewing instance of locality ===
=== Date of latest edit for every item, according to WQS ===
 
<sparql tryit="1">
#title:latest edits dates for wikibase items
 
## because of WQS disappearing data bugs this may not always match the latest edit in the page history
 
SELECT ?item ?date ?dateLabel
WHERE {
  ?item wikibase:timestamp ?date .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?date
 
</sparql>
 
 
 
 
 
=== Questions ===


<sparql tryit="1">
<sparql tryit="1">
 
# how many i/o locality don't have a wikidata id?
#title:asking questions
 
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
Line 288: Line 332:
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpsv: <https://beyond-notability.wikibase.cloud/prop/statement/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
SELECT ?personLabel ?propLabel ?link ?question


#title:i/o locality
SELECT distinct ?itemLabel ?item ?wd_id ?adminLabel ?bn_geo
WHERE {   
WHERE {   
  ?person bnwdt:P3 bnwd:Q3 .
 
  ?person ?p ?s .
      ?prop wikibase:claim ?p;     
        wikibase:statementProperty ?ps.     
         
  # direct link to relevant part of page
        BIND (REPLACE(STR(?prop), "^.*/([^/]*)$", "$1") as ?pid).
        bind(iri(concat(str(?person), "#", ?pid)) as ?link ) .
    
    
   # the question
  ?item bnwdt:P12 bnwd:Q2147 . # has i/o locality (could have other i/o as well?)
    ?s bnpq:P157 ?question .   
 
 
  #optional { ?item bnwdt:P12 ?io .
       
  #        #filter not exists { ?item bnwdt:P12 bnwd:Q2147 . } # this doesn't work... ??? should be only a handful.
  #        } # check io other than locality
 
   # what props do they have: 945 P117 wikidata id; 919 P33 admin territory; 9 P153 coord location
  #?item ?p ?s .
  #    ?prop wikibase:claim ?p.
 
  optional { ?item bnwdt:P117 ?wd_id . }
  optional { ?item bnwdt:P14 ?described . } # to check for described at url instead of wd.  
   optional { ?item bnwdt:P33 ?admin . } # admin territory; some multi
  optional { ?item bnwdt:P153 ?bn_geo . }
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
}
}


order by ?personLabel
ORDER BY ?itemLabel ?item
</sparql>
</sparql>


== Dates ==
== Dates ==
Line 723: Line 765:
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,308:
}
}
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>
590

edits