[addresses] adding the ability to hyphenate the generated unit/floor numbers, either for ranges or simple hyphenated numbers, including hyphenated variants of the letter + number or number + letter forms. Implementing for English but something similar can be done in the other configs.
This commit is contained in:
@@ -29,6 +29,10 @@ class Staircase(NumberedComponent):
|
||||
if num_type == cls.NUMERIC:
|
||||
number = weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
||||
return safe_decode(number)
|
||||
elif num_type == cls.HYPHENATED_NUMBER:
|
||||
number = weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
||||
number2 = number + weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
||||
return u'{}-{}'.format(number, number2)
|
||||
else:
|
||||
alphabet = address_config.get_property('alphabet', language, country=country, default=latin_alphabet)
|
||||
alphabet_probability = address_config.get_property('alphabet_probability', language, country=country, default=None)
|
||||
@@ -41,7 +45,13 @@ class Staircase(NumberedComponent):
|
||||
number = weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
||||
|
||||
whitespace_probability = float(num_type_props.get('whitespace_probability', 0.0))
|
||||
whitespace_phrase = six.u(' ') if whitespace_probability and random.random() < whitespace_probability else six.u('')
|
||||
hyphen_probability = float(num_type_props.get('hyphen_probability', 0.0))
|
||||
whitespace_phrase = u''
|
||||
r = random.random()
|
||||
if r < whitespace_probability:
|
||||
whitespace_phrase = u' '
|
||||
elif r < (whitespace_probability + hyphen_probability):
|
||||
whitespace_phrase = u'-'
|
||||
|
||||
if num_type == cls.ALPHA_PLUS_NUMERIC:
|
||||
return six.u('{}{}{}').format(letter, whitespace_phrase, number)
|
||||
|
||||
Reference in New Issue
Block a user