[openaddresses] abbreviate states as well in OpenAddresses when full version is specified

This commit is contained in:
Al
2016-12-20 17:24:06 -05:00
parent 1cba89a99b
commit cc4098fb05
2 changed files with 15 additions and 3 deletions

View File

@@ -770,16 +770,22 @@ class AddressComponents(object):
return True
return False
def abbreviate_admin_components(self, address_components, country, language, hyphenation=True):
def abbreviated_state(self, state, country, language):
abbreviate_state_prob = float(nested_get(self.config, ('state', 'abbreviated_probability')))
if random.random() < abbreviate_state_prob:
state = state_abbreviations.get_abbreviation(country, language, state, default=state)
return state
def abbreviate_admin_components(self, address_components, country, language, hyphenation=True):
abbreviate_toponym_prob = float(nested_get(self.config, ('boundaries', 'abbreviate_toponym_probability')))
for component, val in six.iteritems(address_components):
if component not in AddressFormatter.BOUNDARY_COMPONENTS:
continue
if component == AddressFormatter.STATE and random.random() < abbreviate_state_prob:
val = state_abbreviations.get_abbreviation(country, language, val, default=val)
if component == AddressFormatter.STATE:
val = self.abbreviated_state(val, country, language)
else:
val = abbreviate(toponym_abbreviations_gazetteer, val, language, abbreviate_prob=abbreviate_toponym_prob)
if hyphenation:

View File

@@ -436,6 +436,12 @@ class OpenAddressesFormatter(object):
if address_state:
components[AddressFormatter.STATE] = address_state
state = components.get(AddressFormatter.STATE)
if state:
state = self.components.abbreviated_state(state, country, language)
if state:
components[AddressFormatter.STATE] = state
# This is expensive, so only turn on for files that don't supply their own city names
# or for which those names are flawed
osm_components = []