User:Stefan Kühn/HASC

All HASC Data in Wikidata edit

#-----------------------------------------------------
# All HASC Data in Wikidata
#-----------------------------------------------------
#defaultView:Table;Map
SELECT ?hasc ?item ?itemLabel ?itemDescription ?countryLabel ?coordinate
WHERE
{
    ?item wdt:P8119 ?hasc .                     # hasc
    OPTIONAL { ?item wdt:P625 ?coordinate. }    # coordinate
    OPTIONAL { ?item wdt:P17  ?country. }       # country
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?hasc
Try it!

All Nuts Data in Wikidata for one country edit

#-----------------------------------------------------
# All Nuts Data in Wikidata for one country
#-----------------------------------------------------
#defaultView:Table;Map
SELECT  ?item ?itemLabel ?itemDescription ?nuts ?countryLabel ?coordinate
WHERE
{
    ?item wdt:P17  ?country.                   # country
    FILTER(?country = wd:Q183)                 # country = Germany   
    OPTIONAL { ?item wdt:P605 ?nuts . }        # nuts
    OPTIONAL { ?item wdt:P625 ?coordinate. }   # coordinate
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?nuts
Try it!

All HASC Data with 5 characters edit

#-----------------------------------------------------
# All HASC Data in Wikidata with 5 characters
#-----------------------------------------------------
#defaultView:Map;Table
SELECT ?hasc ?item ?itemLabel ?itemDescription ?countryLabel ?coordinate
WHERE
{
    ?item wdt:P8119 ?hasc .                     # hasc
    FILTER(REGEX(STR(?hasc), "^[A-Z]{2}.[A-Z]{2}$","i")) 
    OPTIONAL { ?item wdt:P625 ?coordinate. }    # coordinate
    OPTIONAL { ?item wdt:P17  ?country. }       # country
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?hasc
Try it!

All HASC Data with 8 characters edit

#-----------------------------------------------------
# All HASC Data in Wikidata with 8 characters
#-----------------------------------------------------
#defaultView:Map;Table
SELECT ?hasc ?item ?itemLabel ?itemDescription ?countryLabel ?coordinate
WHERE
{
    ?item wdt:P8119 ?hasc .                     # hasc
    FILTER(REGEX(STR(?hasc), "^[A-Z]{2}.[A-Z]{2}.[A-Z]{2}$","i")) 
    OPTIONAL { ?item wdt:P625 ?coordinate. }    # coordinate
    OPTIONAL { ?item wdt:P17  ?country. }       # country
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?hasc
Try it!

All HASC Data with seperate code for country, region and subregion edit

#-----------------------------------------------------
# All HASC Data with seperate code for country, region and subregion
#-----------------------------------------------------
#defaultView:Map;Table
SELECT ?item ?itemLabel ?itemDescription ?hasc ?country_code ?region_code ?subregion_code
WHERE
{
    ?item wdt:P8119 ?hasc .                     # hasc
    #STRLEN("http://www.wikidata.org/entity/Q")+1)
    BIND(SUBSTR(?hasc,1,2) AS ?country_code).
    BIND(SUBSTR(?hasc,4,2) AS ?region_code).
    BIND(SUBSTR(?hasc,7,2) AS ?subregion_code).
    #OPTIONAL { ?item wdt:P625 ?coordinate. }    # coordinate
    #OPTIONAL { ?item wdt:P17  ?country. }       # country
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?hasc
Try it!

Items with HASC and no coordinates edit

#-----------------------------------------------------
# All items with HASC and no coordinates
#-----------------------------------------------------
#defaultView:Table
SELECT ?item ?itemLabel ?itemDescription ?hasc ?coordinate
WHERE
{
    ?item wdt:P8119 ?hasc .                     # hasc
    OPTIONAL {?item wdt:P625 ?coordinate. }     # coordinate
    FILTER(!BOUND(?coordinate)).
    
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?hasc
Try it!

Items with HASC and end date edit

#-----------------------------------------------------
# Items with HASC and end date
#-----------------------------------------------------
#defaultView:Table;Map
SELECT ?hasc ?item ?itemLabel ?countryLabel ?enddate ?continued_by ?continued_byLabel ?coordinate
WHERE
{
    ?item wdt:P8119 ?hasc .                       # hasc
    ?item wdt:P576 ?enddate.                      # enddate
     OPTIONAL { ?item wdt:P1366 ?continued_by. }  # continued by
    OPTIONAL { ?item wdt:P625 ?coordinate. }      # coordinate
    OPTIONAL { ?item wdt:P17  ?country. }         # country
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
order by ?enddate
Try it!

Human settlement and HASC edit

#-----------------------------------------------------
# Human settlement and HASC
#-----------------------------------------------------

SELECT DISTINCT ?itemLabel ?hasc
WITH
{
  # Subquery to get all values of hasc in Germany (DE) 
  SELECT ?region ?hasc
  WHERE
  {
    ?region wdt:P8119 ?hasc .
    FILTER(REGEX(STR(?hasc), "^DE.[A-Z]{2}.[A-Z]{2}$","i")) 
    ?region wdt:P17 wd:Q183 . # country is Germany
  }
  #ORDER BY ?hasc
  #OFFSET 0
  #LIMIT 50
} AS %hasc
WHERE
{
  INCLUDE %hasc
  ?item wdt:P131 * ?region .
  #?item wdt:P31 / wdt:P279 * wd:Q486972 . # ?item is a subclass of human settlement
  VALUES ?instance_of { 
    wd:Q253019      # Ortsteil
    wd:Q486972      # Siedlung
    wd:Q262166      # Gemeinde in Deutschland
    wd:Q123705      # Stadtviertel
  } 
  ?item wdt:P31 ?instance_of .  
  #hint:Prior hint:gearing "forward" . 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de". }
}
Try it!