[addresses] Roman numerals can be returned by Floor.random, relaxing the Zipfian distribution on floors so we get higher floors
This commit is contained in:
@@ -6,6 +6,7 @@ from geodata.addresses.config import address_config
|
||||
from geodata.addresses.numbering import NumberedComponent, sample_alphabet, latin_alphabet
|
||||
from geodata.encoding import safe_decode
|
||||
from geodata.math.sampling import weighted_choice, zipfian_distribution, cdf
|
||||
from geodata.numbers.spellout import numeric_expressions
|
||||
|
||||
|
||||
class Floor(NumberedComponent):
|
||||
@@ -15,7 +16,7 @@ class Floor(NumberedComponent):
|
||||
max_floors = 10
|
||||
max_basements = 2
|
||||
numbered_floors = range(max_floors + 1) + range(-1, -max_basements - 1, -1)
|
||||
floor_probs = zipfian_distribution(len(numbered_floors), 2.0)
|
||||
floor_probs = zipfian_distribution(len(numbered_floors), 0.75)
|
||||
floor_probs_cdf = cdf(floor_probs)
|
||||
|
||||
# For use with letters e.g. A0 is probably not as common
|
||||
@@ -53,6 +54,12 @@ class Floor(NumberedComponent):
|
||||
|
||||
if num_type == cls.NUMERIC:
|
||||
return safe_decode(number)
|
||||
elif num_type == cls.ROMAN_NUMERAL:
|
||||
roman_numeral = numeric_expressions.roman_numeral(number)
|
||||
if roman_numeral is not None:
|
||||
return roman_numeral
|
||||
else:
|
||||
return safe_decode(number)
|
||||
else:
|
||||
alphabet = address_config.get_property('alphabet', language, country=country, default=latin_alphabet)
|
||||
letter = sample_alphabet(alphabet)
|
||||
|
||||
@@ -117,6 +117,7 @@ class NumberedComponent(object):
|
||||
ALPHA = 'alpha'
|
||||
ALPHA_PLUS_NUMERIC = 'alpha_plus_numeric'
|
||||
NUMERIC_PLUS_ALPHA = 'numeric_plus_alpha'
|
||||
ROMAN_NUMERAL = 'roman_numeral'
|
||||
|
||||
@classmethod
|
||||
def choose_alphanumeric_type(cls, key, language, country=None):
|
||||
@@ -127,7 +128,7 @@ class NumberedComponent(object):
|
||||
values = []
|
||||
probs = []
|
||||
|
||||
for num_type in (cls.NUMERIC, cls.ALPHA, cls.ALPHA_PLUS_NUMERIC, cls.NUMERIC_PLUS_ALPHA):
|
||||
for num_type in (cls.NUMERIC, cls.ALPHA, cls.ALPHA_PLUS_NUMERIC, cls.NUMERIC_PLUS_ALPHA, cls.ROMAN_NUMERAL):
|
||||
key = '{}_probability'.format(num_type)
|
||||
prob = alphanumeric_props.get(key)
|
||||
if prob is not None:
|
||||
|
||||
Reference in New Issue
Block a user