From a20b43cd28de6c7ea824b4145cb9a27eebc11886 Mon Sep 17 00:00:00 2001 From: Al Date: Thu, 19 May 2016 02:40:19 -0400 Subject: [PATCH] [addresses] only use ordinal for digits --- scripts/geodata/addresses/components.py | 2 +- scripts/geodata/addresses/numbering.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/geodata/addresses/components.py b/scripts/geodata/addresses/components.py index bce99499..4c63a2f5 100644 --- a/scripts/geodata/addresses/components.py +++ b/scripts/geodata/addresses/components.py @@ -297,7 +297,7 @@ class AddressComponents(object): combo = weighted_choice(values, probs) if combo is not None: components = OrderedDict.fromkeys(combo['components']).keys() - if not all((c in address_components and (c in generated_components or address_components[c].isdigit()) for c in components)): + if not all((c in address_components and (c in generated_components or self.is_numeric(address_components[c])) for c in components)): return None values = [] diff --git a/scripts/geodata/addresses/numbering.py b/scripts/geodata/addresses/numbering.py index 3c43f946..6aba95fb 100644 --- a/scripts/geodata/addresses/numbering.py +++ b/scripts/geodata/addresses/numbering.py @@ -192,7 +192,7 @@ class NumberedComponent(object): # If we're using something like "Floor A" or "Unit 2L", remove ordinal/affix items if is_alpha: values, probs = zip(*[(v, p) for v, p in zip(values, probs) if v in ('numeric', 'null', 'standalone')]) - total = sum(probs) + total = float(sum(probs)) probs = [p / total for p in probs] probs = cdf(probs) @@ -232,12 +232,14 @@ class NumberedComponent(object): whitespace_default = True + num = safe_decode(num) + if num_type == 'numeric_affix': phrase = props['affix'] if props.get('upper_case', True): phrase = phrase.upper() whitespace_default = False - elif num_type == 'ordinal': + elif num_type == 'ordinal' and safe_decode(num).isdigit(): num = ordinal_expressions.suffixed_number(num, language, gender=props.get('gender', None)) if random.random() < props.get('null_phrase_probability', 0.0):