[formatter] adding house_number_before_road method to AddressFormatter
This commit is contained in:
@@ -207,6 +207,8 @@ class AddressFormatter(object):
|
|||||||
config = yaml.load(open(os.path.join(self.formatter_repo_path,
|
config = yaml.load(open(os.path.join(self.formatter_repo_path,
|
||||||
'conf', 'countries', 'worldwide.yaml')))
|
'conf', 'countries', 'worldwide.yaml')))
|
||||||
self.country_aliases = {}
|
self.country_aliases = {}
|
||||||
|
self.house_number_ordering = {}
|
||||||
|
|
||||||
for key in list(config):
|
for key in list(config):
|
||||||
country = key
|
country = key
|
||||||
language = None
|
language = None
|
||||||
@@ -231,6 +233,18 @@ class AddressFormatter(object):
|
|||||||
else:
|
else:
|
||||||
address_template = value
|
address_template = value
|
||||||
config[country] = self.add_postprocessing_tags(value, country, language=language)
|
config[country] = self.add_postprocessing_tags(value, country, language=language)
|
||||||
|
|
||||||
|
try:
|
||||||
|
house_number_index = address_template.index(self.tag_token(self.HOUSE_NUMBER))
|
||||||
|
road_index = address_template.index(self.tag_token(self.ROAD))
|
||||||
|
|
||||||
|
if house_number_index < road_index:
|
||||||
|
self.house_number_ordering[key.lower()] = -1
|
||||||
|
else:
|
||||||
|
self.house_number_ordering[key.lower()] = 1
|
||||||
|
except ValueError:
|
||||||
|
self.house_number_ordering[key.lower()] = 0
|
||||||
|
|
||||||
self.country_formats = config
|
self.country_formats = config
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
@@ -302,6 +316,26 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
return component_insertions
|
return component_insertions
|
||||||
|
|
||||||
|
def house_number_before_road(self, country, language=None):
|
||||||
|
key = value = None
|
||||||
|
if language is not None:
|
||||||
|
key = six.u('_').join((country.lower(), language.lower()))
|
||||||
|
if key in self.house_number_ordering:
|
||||||
|
value = self.house_number_ordering[key]
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
key = country
|
||||||
|
if key in self.house_number_ordering:
|
||||||
|
value = self.house_number_ordering[key]
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
value = 0
|
||||||
|
|
||||||
|
if value <= 0:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def conditional_insertion_probs(self, conditionals):
|
def conditional_insertion_probs(self, conditionals):
|
||||||
conditional_insertions = defaultdict(OrderedDict)
|
conditional_insertions = defaultdict(OrderedDict)
|
||||||
for component, value in six.iteritems(conditionals):
|
for component, value in six.iteritems(conditionals):
|
||||||
|
|||||||
Reference in New Issue
Block a user