[addresses] Implementing whitespace_probability and ordinal_suffix probability for Roman numerals
This commit is contained in:
@@ -125,7 +125,12 @@ class Digits(object):
|
||||
elif digit_type == cls.SPELLOUT:
|
||||
return cls.rewrite_spellout(d, lang, num_type, props)
|
||||
elif digit_type == cls.ROMAN_NUMERAL:
|
||||
return cls.rewrite_roman_numeral(d)
|
||||
roman_numeral = cls.rewrite_roman_numeral(d)
|
||||
if random.random() < props.get('ordinal_suffix_probability', 0.0):
|
||||
ordinal_suffix = ordinal_expressions.get_suffix(d, lang, gender=props.get('gender', None))
|
||||
if ordinal_suffix:
|
||||
roman_numeral = six.u('{}{}').format(roman_numeral, ordinal_suffix)
|
||||
return roman_numeral
|
||||
elif digit_type == cls.UNICODE_FULL_WIDTH:
|
||||
return cls.rewrite_full_width(d)
|
||||
else:
|
||||
@@ -175,6 +180,10 @@ class NumericPhrase(object):
|
||||
|
||||
direction = props['direction']
|
||||
whitespace = props.get('whitespace', whitespace_default)
|
||||
whitespace_probability = props.get('whitespace_probability')
|
||||
if whitespace_probability is not None:
|
||||
whitespace = random.random() < whitespace_probability
|
||||
|
||||
if props.get('title_case', True):
|
||||
# Title case unless the config specifies otherwise
|
||||
phrase = phrase.title()
|
||||
@@ -391,6 +400,10 @@ class NumberedComponent(object):
|
||||
direction = props['direction']
|
||||
whitespace = props.get('whitespace', whitespace_default)
|
||||
|
||||
whitespace_probability = props.get('whitespace_probability')
|
||||
if whitespace_probability is not None:
|
||||
whitespace = random.random() < whitespace_probability
|
||||
|
||||
# Occasionally switch up if direction_probability is specified
|
||||
if random.random() > props.get('direction_probability', 1.0):
|
||||
if direction == 'left':
|
||||
|
||||
@@ -93,11 +93,16 @@ class OrdinalExpressions(object):
|
||||
|
||||
return trie.search_suffix(str(num))
|
||||
|
||||
def suffixed_number(self, num, lang, gender=None, category=None):
|
||||
def get_suffix(self, num, lang, gender=None, category=None):
|
||||
suffixes = self.get_suffixes(num, lang, gender=gender, category=category)
|
||||
if not suffixes:
|
||||
return None
|
||||
suffix = random.choice(suffixes)
|
||||
return random.choice(suffixes)
|
||||
|
||||
def suffixed_number(self, num, lang, gender=None, category=None):
|
||||
suffix = self.get_suffix(num, lang, gender=gender, category=category)
|
||||
if not suffix:
|
||||
return None
|
||||
return six.u('{}{}').format(safe_decode(num), safe_decode(suffix))
|
||||
|
||||
ordinal_expressions = OrdinalExpressions()
|
||||
|
||||
Reference in New Issue
Block a user