From cad1f95bbb0a9a118ead3c09c57a761633f56d4d Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 14 Aug 2015 10:21:12 -0400 Subject: [PATCH] [osm] Making minimal_only the default in formatted addresses, expanding list of acceptable combinations of address fields --- scripts/geodata/osm/osm_address_training_data.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/geodata/osm/osm_address_training_data.py b/scripts/geodata/osm/osm_address_training_data.py index e2a6f0fe..3222336c 100644 --- a/scripts/geodata/osm/osm_address_training_data.py +++ b/scripts/geodata/osm/osm_address_training_data.py @@ -119,7 +119,11 @@ def read_osm_json(filename): class AddressFormatter(object): ''' Approximate Python port of lokku's Geo::Address::Formatter ''' - MINIMAL_COMPONENT_KEYS = ('road', 'house_number') + MINIMAL_COMPONENT_KEYS = [ + ('road', 'house_number'), + ('road', 'house'), + ('road', 'postcode') + ] splitter = ' | ' @@ -201,7 +205,10 @@ class AddressFormatter(object): return output def minimal_components(self, components): - return all((c in components for c in self.MINIMAL_COMPONENT_KEYS)) + for component_list in self.MINIMAL_COMPONENT_KEYS: + if all((c in components for c in component_list)): + return True + return False def apply_replacements(self, template, components): if not template.get('replace'): @@ -227,7 +234,7 @@ class AddressFormatter(object): text = re.sub(regex, replacement, text) return text - def format_address(self, country, components, minimal_only=False, tag_components=True): + def format_address(self, country, components, minimal_only=True, tag_components=True): template = self.config.get(country.upper()) if not template: return None