From da4fe37fb48f30ac27282457caf2a010cc74132f Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 11 Dec 2016 15:20:20 -0500 Subject: [PATCH] [addresses] option to add city points, no random keys for state_district if city or replacement is not present --- scripts/geodata/addresses/components.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/geodata/addresses/components.py b/scripts/geodata/addresses/components.py index 5b9a1311..94c9f707 100644 --- a/scripts/geodata/addresses/components.py +++ b/scripts/geodata/addresses/components.py @@ -793,6 +793,7 @@ class AddressComponents(object): language_suffix='', normalize_languages=None, random_key=True, + add_city_points=True, always_use_full_names=False, drop_duplicate_city_names=True, ): @@ -843,14 +844,17 @@ class AddressComponents(object): existing_city_name = address_components.get(AddressFormatter.CITY) - if not existing_city_name and AddressFormatter.CITY not in grouped_osm_components: + if add_city_points and not existing_city_name and AddressFormatter.CITY not in grouped_osm_components: self.add_city_and_equivalent_points(grouped_osm_components, osm_components, country, latitude, longitude) + city_replacements = place_config.city_replacements(country) + have_city = AddressFormatter.CITY in grouped_osm_components or set(grouped_osm_components) & set(city_replacements) + for component, components_values in grouped_osm_components.iteritems(): seen = set() for component_value in components_values: - if random_key: + if random_key and not (component == AddressFormatter.STATE_DISTRICT and not have_city): key, raw_key = self.pick_random_name_key(component_value, component, suffix=language_suffix) else: key, raw_key = name_key, raw_name_key