add normalize_country_name method

This commit is contained in:
rolux 2013-02-09 10:07:38 +05:30
parent f7d72335ef
commit 340c7fb924

134
ox/geo.py
View file

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