add normalize_country_name method
This commit is contained in:
parent
f7d72335ef
commit
340c7fb924
1 changed files with 1377 additions and 1291 deletions
134
ox/geo.py
134
ox/geo.py
|
@ -14,7 +14,12 @@ Ox.COUNTRIES.forEach(function(country) {
|
|||
name: country.name,
|
||||
region: country.region,
|
||||
continent: country.continent
|
||||
};
|
||||
}
|
||||
if (country.googleName || country.imdbName) {
|
||||
countries[country.code].aliases = Ox.compact(Ox.unique(
|
||||
[country.googleName, country.imdbName]
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
Ox.print(JSON.stringify(countries, null, ' '));
|
||||
|
@ -164,7 +169,10 @@ COUNTRIES = {
|
|||
"BN": {
|
||||
"name": "Brunei",
|
||||
"region": "South-Eastern Asia",
|
||||
"continent": "Asia"
|
||||
"continent": "Asia",
|
||||
"aliases": [
|
||||
"Brunei Darussalam"
|
||||
]
|
||||
},
|
||||
"BO": {
|
||||
"name": "Bolivia",
|
||||
|
@ -184,7 +192,10 @@ COUNTRIES = {
|
|||
"BS": {
|
||||
"name": "Bahamas",
|
||||
"region": "Caribbean",
|
||||
"continent": "South America"
|
||||
"continent": "South America",
|
||||
"aliases": [
|
||||
"The Bahamas"
|
||||
]
|
||||
},
|
||||
"BT": {
|
||||
"name": "Bhutan",
|
||||
|
@ -219,12 +230,18 @@ COUNTRIES = {
|
|||
"CC": {
|
||||
"name": "Cocos Islands",
|
||||
"region": "South-Eastern Asia",
|
||||
"continent": "Asia"
|
||||
"continent": "Asia",
|
||||
"aliases": [
|
||||
"Cocos (Keeling) Islands"
|
||||
]
|
||||
},
|
||||
"CD": {
|
||||
"name": "Democratic Republic of the Congo",
|
||||
"region": "Middle Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Democratic Republic of Congo"
|
||||
]
|
||||
},
|
||||
"CF": {
|
||||
"name": "Central African Republic",
|
||||
|
@ -234,7 +251,10 @@ COUNTRIES = {
|
|||
"CG": {
|
||||
"name": "Republic of the Congo",
|
||||
"region": "Middle Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Congo"
|
||||
]
|
||||
},
|
||||
"CH": {
|
||||
"name": "Switzerland",
|
||||
|
@ -244,7 +264,10 @@ COUNTRIES = {
|
|||
"CI": {
|
||||
"name": "Côte d'Ivoire",
|
||||
"region": "Western Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Ivory Coast"
|
||||
]
|
||||
},
|
||||
"CK": {
|
||||
"name": "Cook Islands",
|
||||
|
@ -369,7 +392,10 @@ COUNTRIES = {
|
|||
"EH": {
|
||||
"name": "Sahrawi",
|
||||
"region": "Northern Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Western Sahara"
|
||||
]
|
||||
},
|
||||
"ER": {
|
||||
"name": "Eritrea",
|
||||
|
@ -409,7 +435,10 @@ COUNTRIES = {
|
|||
"FM": {
|
||||
"name": "Micronesia",
|
||||
"region": "Micronesia",
|
||||
"continent": "Oceania"
|
||||
"continent": "Oceania",
|
||||
"aliases": [
|
||||
"Federated States of Micronesia"
|
||||
]
|
||||
},
|
||||
"FO": {
|
||||
"name": "Faroe Islands",
|
||||
|
@ -429,7 +458,10 @@ COUNTRIES = {
|
|||
"GB": {
|
||||
"name": "United Kingdom",
|
||||
"region": "Northern Europe",
|
||||
"continent": "Europe"
|
||||
"continent": "Europe",
|
||||
"aliases": [
|
||||
"UK"
|
||||
]
|
||||
},
|
||||
"GD": {
|
||||
"name": "Grenada",
|
||||
|
@ -469,7 +501,10 @@ COUNTRIES = {
|
|||
"GM": {
|
||||
"name": "Gambia",
|
||||
"region": "Western Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"The Gambia"
|
||||
]
|
||||
},
|
||||
"GN": {
|
||||
"name": "Guinea",
|
||||
|
@ -754,7 +789,10 @@ COUNTRIES = {
|
|||
"MF": {
|
||||
"name": "Saint Martin",
|
||||
"region": "Caribbean",
|
||||
"continent": "South America"
|
||||
"continent": "South America",
|
||||
"aliases": [
|
||||
"Saint Martin (French part)"
|
||||
]
|
||||
},
|
||||
"MG": {
|
||||
"name": "Madagascar",
|
||||
|
@ -769,7 +807,11 @@ COUNTRIES = {
|
|||
"MK": {
|
||||
"name": "Macedonia",
|
||||
"region": "Southern Europe",
|
||||
"continent": "Europe"
|
||||
"continent": "Europe",
|
||||
"aliases": [
|
||||
"Former Yugoslav Republic of Macedonia",
|
||||
"Republic of Macedonia"
|
||||
]
|
||||
},
|
||||
"ML": {
|
||||
"name": "Mali",
|
||||
|
@ -779,7 +821,10 @@ COUNTRIES = {
|
|||
"MM": {
|
||||
"name": "Myanmar",
|
||||
"region": "South-Eastern Asia",
|
||||
"continent": "Asia"
|
||||
"continent": "Asia",
|
||||
"aliases": [
|
||||
"Burma"
|
||||
]
|
||||
},
|
||||
"MN": {
|
||||
"name": "Mongolia",
|
||||
|
@ -789,7 +834,10 @@ COUNTRIES = {
|
|||
"MO": {
|
||||
"name": "Macau",
|
||||
"region": "Eastern Asia",
|
||||
"continent": "Asia"
|
||||
"continent": "Asia",
|
||||
"aliases": [
|
||||
"Macao"
|
||||
]
|
||||
},
|
||||
"MP": {
|
||||
"name": "Northern Mariana Islands",
|
||||
|
@ -954,7 +1002,10 @@ COUNTRIES = {
|
|||
"PN": {
|
||||
"name": "Pitcairn Islands",
|
||||
"region": "Polynesia",
|
||||
"continent": "Oceania"
|
||||
"continent": "Oceania",
|
||||
"aliases": [
|
||||
"Pitcairn"
|
||||
]
|
||||
},
|
||||
"PR": {
|
||||
"name": "Puerto Rico",
|
||||
|
@ -964,7 +1015,11 @@ COUNTRIES = {
|
|||
"PS": {
|
||||
"name": "Palestine",
|
||||
"region": "Western Asia",
|
||||
"continent": "Asia"
|
||||
"continent": "Asia",
|
||||
"aliases": [
|
||||
"Palestinian Territories",
|
||||
"Occupied Palestinian Territory"
|
||||
]
|
||||
},
|
||||
"PT": {
|
||||
"name": "Portugal",
|
||||
|
@ -1044,7 +1099,10 @@ COUNTRIES = {
|
|||
"SH": {
|
||||
"name": "Saint Helena, Ascension and Tristan da Cunha",
|
||||
"region": "Western Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Saint Helena"
|
||||
]
|
||||
},
|
||||
"SI": {
|
||||
"name": "Slovenia",
|
||||
|
@ -1094,7 +1152,10 @@ COUNTRIES = {
|
|||
"ST": {
|
||||
"name": "São Tomé and Príncipe",
|
||||
"region": "Middle Africa",
|
||||
"continent": "Africa"
|
||||
"continent": "Africa",
|
||||
"aliases": [
|
||||
"Sao Tome and Principe"
|
||||
]
|
||||
},
|
||||
"SV": {
|
||||
"name": "El Salvador",
|
||||
|
@ -1214,7 +1275,10 @@ COUNTRIES = {
|
|||
"UK": {
|
||||
"name": "United Kingdom",
|
||||
"region": "Northern Europe",
|
||||
"continent": "Europe"
|
||||
"continent": "Europe",
|
||||
"aliases": [
|
||||
"UK"
|
||||
]
|
||||
},
|
||||
"UM": {
|
||||
"name": "United States Minor Outlying Islands",
|
||||
|
@ -1224,7 +1288,10 @@ COUNTRIES = {
|
|||
"US": {
|
||||
"name": "United States",
|
||||
"region": "Northern America",
|
||||
"continent": "North America"
|
||||
"continent": "North America",
|
||||
"aliases": [
|
||||
"USA"
|
||||
]
|
||||
},
|
||||
"UY": {
|
||||
"name": "Uruguay",
|
||||
|
@ -1239,7 +1306,10 @@ COUNTRIES = {
|
|||
"VA": {
|
||||
"name": "Vatican City",
|
||||
"region": "Southern Europe",
|
||||
"continent": "Europe"
|
||||
"continent": "Europe",
|
||||
"aliases": [
|
||||
"Holy See (Vatican City State)"
|
||||
]
|
||||
},
|
||||
"VC": {
|
||||
"name": "Saint Vincent and the Grenadines",
|
||||
|
@ -1259,7 +1329,10 @@ COUNTRIES = {
|
|||
"VI": {
|
||||
"name": "United States Virgin Islands",
|
||||
"region": "Caribbean",
|
||||
"continent": "South America"
|
||||
"continent": "South America",
|
||||
"aliases": [
|
||||
"US Virgin Islands"
|
||||
]
|
||||
},
|
||||
"VN": {
|
||||
"name": "Vietnam",
|
||||
|
@ -1284,7 +1357,10 @@ COUNTRIES = {
|
|||
"XK": {
|
||||
"name": "Kosovo",
|
||||
"region": "Southern Europe",
|
||||
"continent": "Europe"
|
||||
"continent": "Europe",
|
||||
"aliases": [
|
||||
"Kosova (Kosovo)"
|
||||
]
|
||||
},
|
||||
"YE": {
|
||||
"name": "Yemen",
|
||||
|
@ -1340,3 +1416,13 @@ def get_country(country_code):
|
|||
def get_country_name(country_code):
|
||||
country_code = country_code.upper()
|
||||
return COUNTRIES[country_code]['name'] if country_code in COUNTRIES else ''
|
||||
|
||||
def normalize_country_name(country_name):
|
||||
name = None
|
||||
for code, country in COUNTRIES.iteritems():
|
||||
if country_name == country['name'] or (
|
||||
'aliases' in country and country_name in country['aliases']
|
||||
):
|
||||
name = country['name']
|
||||
break
|
||||
return name
|
||||
|
|
Loading…
Reference in a new issue