[addresses] only use ordinal for digits

This commit is contained in:
Al
2016-05-19 02:40:19 -04:00
parent def886858d
commit dde8801b3f
2 changed files with 5 additions and 3 deletions

View File

@@ -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 = []

View File

@@ -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):