[addresses] Updates to unit directional probabilities and adding quadrant addresses for units like 1RF
This commit is contained in:
@@ -719,8 +719,8 @@ directions:
|
|||||||
affix: r
|
affix: r
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.05
|
whitespace_probability: 0.05
|
||||||
numeric_probability: 0.2
|
numeric_probability: 0.05
|
||||||
numeric_affix_probability: 0.8
|
numeric_affix_probability: 0.95
|
||||||
left: &left
|
left: &left
|
||||||
canonical: left
|
canonical: left
|
||||||
abbreviated: l
|
abbreviated: l
|
||||||
@@ -732,8 +732,8 @@ directions:
|
|||||||
affix: l
|
affix: l
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.05
|
whitespace_probability: 0.05
|
||||||
numeric_probability: 0.2
|
numeric_probability: 0.05
|
||||||
numeric_affix_probability: 0.8
|
numeric_affix_probability: 0.95
|
||||||
rear: &rear
|
rear: &rear
|
||||||
canonical: rear
|
canonical: rear
|
||||||
abbreviated: r
|
abbreviated: r
|
||||||
@@ -745,8 +745,8 @@ directions:
|
|||||||
affix: r
|
affix: r
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.05
|
whitespace_probability: 0.05
|
||||||
numeric_probability: 0.2
|
numeric_probability: 0.05
|
||||||
numeric_affix_probability: 0.8
|
numeric_affix_probability: 0.95
|
||||||
front: &front
|
front: &front
|
||||||
canonical: front
|
canonical: front
|
||||||
abbreviated: frnt
|
abbreviated: frnt
|
||||||
@@ -758,8 +758,8 @@ directions:
|
|||||||
affix: f
|
affix: f
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.05
|
whitespace_probability: 0.05
|
||||||
numeric_probability: 0.2
|
numeric_probability: 0.05
|
||||||
numeric_affix_probability: 0.8
|
numeric_affix_probability: 0.95
|
||||||
alternatives:
|
alternatives:
|
||||||
- alternative: *right
|
- alternative: *right
|
||||||
probability: 0.45
|
probability: 0.45
|
||||||
@@ -770,6 +770,22 @@ directions:
|
|||||||
- alternative: *rear
|
- alternative: *rear
|
||||||
probability: 0.05
|
probability: 0.05
|
||||||
|
|
||||||
|
anteroposterior:
|
||||||
|
alternatives:
|
||||||
|
- alternative: *front
|
||||||
|
probability: 0.5
|
||||||
|
- alternative: *rear
|
||||||
|
probability: 0.5
|
||||||
|
|
||||||
|
lateral:
|
||||||
|
alternatives:
|
||||||
|
- alternative: *left
|
||||||
|
probability: 0.5
|
||||||
|
- alternative: *right
|
||||||
|
probability: 0.5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cardinal_directions:
|
cardinal_directions:
|
||||||
east: &east
|
east: &east
|
||||||
canonical: east
|
canonical: east
|
||||||
@@ -1184,10 +1200,19 @@ units:
|
|||||||
# Separate random probability for adding directions like 2L, 2R, etc.
|
# Separate random probability for adding directions like 2L, 2R, etc.
|
||||||
add_direction: true
|
add_direction: true
|
||||||
add_direction_probability: 0.1
|
add_direction_probability: 0.1
|
||||||
# Add directions only for plain numbers
|
|
||||||
|
# Add directions for plain numbers
|
||||||
add_direction_numeric: true
|
add_direction_numeric: true
|
||||||
|
# Add direction only e.g. Unit Left
|
||||||
add_direction_standalone: true
|
add_direction_standalone: true
|
||||||
|
|
||||||
|
# Separate random probability for adding quadrant units like 2RF 2RR 2LF 2LR
|
||||||
|
add_quadrant: true
|
||||||
|
add_quadrant_probability: 0.001
|
||||||
|
add_quadrant_first_direction: lateral
|
||||||
|
|
||||||
|
add_quadrant_numeric: true
|
||||||
|
|
||||||
# If there are 10 floors, create unit numbers like #301 or #1032
|
# If there are 10 floors, create unit numbers like #301 or #1032
|
||||||
use_floor_probability: 0.35
|
use_floor_probability: 0.35
|
||||||
|
|
||||||
@@ -1232,17 +1257,6 @@ units:
|
|||||||
lot_plus_parcel_probability: 0.02
|
lot_plus_parcel_probability: 0.02
|
||||||
parcel_plus_lot_probability: 0.02
|
parcel_plus_lot_probability: 0.02
|
||||||
|
|
||||||
directional:
|
|
||||||
modifier:
|
|
||||||
direction: right # e.g. 1
|
|
||||||
numeric_probability: 0.1
|
|
||||||
numeric_affix_probability: 0.9
|
|
||||||
alternatives:
|
|
||||||
- alternative: *right
|
|
||||||
- alternative: *left
|
|
||||||
- alternative: *rear
|
|
||||||
- alternative: *front
|
|
||||||
|
|
||||||
standalone:
|
standalone:
|
||||||
sample: false
|
sample: false
|
||||||
default: *penthouse
|
default: *penthouse
|
||||||
|
|||||||
@@ -442,8 +442,8 @@ directions:
|
|||||||
affix: d
|
affix: d
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.1
|
whitespace_probability: 0.1
|
||||||
numeric_probability: 0.7
|
numeric_probability: 0.4
|
||||||
numeric_affix_probability: 0.3
|
numeric_affix_probability: 0.6
|
||||||
left: &izquierda
|
left: &izquierda
|
||||||
canonical: izquierda
|
canonical: izquierda
|
||||||
abbreviated: izq
|
abbreviated: izq
|
||||||
@@ -457,8 +457,8 @@ directions:
|
|||||||
affix: i
|
affix: i
|
||||||
direction: right
|
direction: right
|
||||||
whitespace_probability: 0.1
|
whitespace_probability: 0.1
|
||||||
numeric_probability: 0.7
|
numeric_probability: 0.4
|
||||||
numeric_affix_probability: 0.3
|
numeric_affix_probability: 0.6
|
||||||
rear: &trasera
|
rear: &trasera
|
||||||
canonical: trasera
|
canonical: trasera
|
||||||
abbreviated: tras
|
abbreviated: tras
|
||||||
@@ -487,6 +487,20 @@ directions:
|
|||||||
- alternative: *frente
|
- alternative: *frente
|
||||||
probability: 0.05
|
probability: 0.05
|
||||||
|
|
||||||
|
anteroposterior:
|
||||||
|
alternatives:
|
||||||
|
- alternative: *frente
|
||||||
|
probability: 0.5
|
||||||
|
- alternative: *trasera
|
||||||
|
probability: 0.5
|
||||||
|
|
||||||
|
lateral:
|
||||||
|
alternatives:
|
||||||
|
- alternative: *derecha
|
||||||
|
probability: 0.5
|
||||||
|
- alternative: *izquierda
|
||||||
|
probability: 0.5
|
||||||
|
|
||||||
cardinal_directions:
|
cardinal_directions:
|
||||||
east: &este
|
east: &este
|
||||||
canonical: este
|
canonical: este
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ class RelativeDirection(NumericPhrase):
|
|||||||
dictionaries = ['unit_directions']
|
dictionaries = ['unit_directions']
|
||||||
|
|
||||||
|
|
||||||
|
class AnteroposteriorDirection(RelativeDirection):
|
||||||
|
key = 'directions.anteroposterior'
|
||||||
|
|
||||||
|
|
||||||
|
class LateralDirection(RelativeDirection):
|
||||||
|
key = 'directions.lateral'
|
||||||
|
|
||||||
|
|
||||||
class CardinalDirection(NumericPhrase):
|
class CardinalDirection(NumericPhrase):
|
||||||
key = 'cardinal_directions'
|
key = 'cardinal_directions'
|
||||||
dictionaries = ['cardinal_directions']
|
dictionaries = ['cardinal_directions']
|
||||||
|
|||||||
@@ -41,8 +41,11 @@ latin_alphabet = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
|
|||||||
class NumericPhrase(object):
|
class NumericPhrase(object):
|
||||||
key = None
|
key = None
|
||||||
|
|
||||||
|
NUMERIC = 'numeric'
|
||||||
|
NUMERIC_AFFIX = 'numeric_affix'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def phrase(cls, number, language, country=None):
|
def pick_phrase_and_type(cls, number, language, country=None):
|
||||||
values, probs = address_config.alternative_probabilities(cls.key, language, dictionaries=cls.dictionaries, country=country)
|
values, probs = address_config.alternative_probabilities(cls.key, language, dictionaries=cls.dictionaries, country=country)
|
||||||
if not values:
|
if not values:
|
||||||
return safe_decode(number) if number is not None else None
|
return safe_decode(number) if number is not None else None
|
||||||
@@ -52,7 +55,7 @@ class NumericPhrase(object):
|
|||||||
values = []
|
values = []
|
||||||
probs = []
|
probs = []
|
||||||
|
|
||||||
for num_type in ('numeric', 'numeric_affix'):
|
for num_type in (cls.NUMERIC, cls.NUMERIC_AFFIX):
|
||||||
key = '{}_probability'.format(num_type)
|
key = '{}_probability'.format(num_type)
|
||||||
prob = phrase_props.get(key, None)
|
prob = phrase_props.get(key, None)
|
||||||
if prob is not None:
|
if prob is not None:
|
||||||
@@ -62,19 +65,16 @@ class NumericPhrase(object):
|
|||||||
probs = cdf(probs)
|
probs = cdf(probs)
|
||||||
|
|
||||||
if len(values) < 2:
|
if len(values) < 2:
|
||||||
num_type = 'numeric'
|
num_type = cls.NUMERIC
|
||||||
else:
|
else:
|
||||||
num_type = weighted_choice(values, probs)
|
num_type = weighted_choice(values, probs)
|
||||||
|
|
||||||
props = phrase_props[num_type]
|
return num_type, phrase, phrase_props[num_type]
|
||||||
|
|
||||||
if num_type == 'numeric':
|
@classmethod
|
||||||
# Numeric phrase the default is with whitespace e.g. "No 1"
|
def combine_with_number(cls, number, phrase, num_type, props, whitespace_default=False):
|
||||||
whitespace_default = True
|
if num_type == cls.NUMERIC_AFFIX:
|
||||||
elif num_type == 'numeric_affix':
|
|
||||||
phrase = props['affix']
|
phrase = props['affix']
|
||||||
# Numeric affix default is no whitespace e.g. "#1"
|
|
||||||
whitespace_default = False
|
|
||||||
|
|
||||||
direction = props['direction']
|
direction = props['direction']
|
||||||
whitespace = props.get('whitespace', whitespace_default)
|
whitespace = props.get('whitespace', whitespace_default)
|
||||||
@@ -96,6 +96,12 @@ class NumericPhrase(object):
|
|||||||
else:
|
else:
|
||||||
return safe_decode(number)
|
return safe_decode(number)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def phrase(cls, number, language, country=None):
|
||||||
|
num_type, phrase, props = cls.pick_phrase_and_type(number, language, country=country)
|
||||||
|
whitespace_default = num_type == cls.NUMERIC
|
||||||
|
return cls.combine_with_number(number, phrase, num_type, props, whitespace_default=whitespace_default)
|
||||||
|
|
||||||
|
|
||||||
class Number(NumericPhrase):
|
class Number(NumericPhrase):
|
||||||
key = 'numbers'
|
key = 'numbers'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import random
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from geodata.addresses.config import address_config
|
from geodata.addresses.config import address_config
|
||||||
from geodata.addresses.directions import RelativeDirection
|
from geodata.addresses.directions import RelativeDirection, LateralDirection, AnteroposteriorDirection
|
||||||
from geodata.addresses.floors import Floor
|
from geodata.addresses.floors import Floor
|
||||||
from geodata.addresses.numbering import NumberedComponent, sample_alphabet, latin_alphabet
|
from geodata.addresses.numbering import NumberedComponent, sample_alphabet, latin_alphabet
|
||||||
from geodata.configs.utils import nested_get
|
from geodata.configs.utils import nested_get
|
||||||
@@ -101,14 +101,63 @@ class Unit(NumberedComponent):
|
|||||||
if add_direction_standalone:
|
if add_direction_standalone:
|
||||||
return RelativeDirection.phrase(None, language, country=country)
|
return RelativeDirection.phrase(None, language, country=country)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_quadrant(cls, key, unit, language, country=None):
|
||||||
|
add_quadrant_probability = address_config.get_property('{}.add_quadrant_probability'.format(key),
|
||||||
|
language, country=country, default=0.0)
|
||||||
|
if not random.random() < add_quadrant_probability:
|
||||||
|
return unit
|
||||||
|
add_quadrant_numeric = address_config.get_property('{}.add_quadrant_numeric'.format(key),
|
||||||
|
language, country=country)
|
||||||
|
try:
|
||||||
|
unit = int(unit)
|
||||||
|
integer_unit = True
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
integer_unit = False
|
||||||
|
|
||||||
|
first_direction = address_config.get_property('{}.add_quadrant_first_direction'.format(key),
|
||||||
|
language, country=country)
|
||||||
|
|
||||||
|
if first_direction == 'lateral':
|
||||||
|
ordering = (LateralDirection, AnteroposteriorDirection)
|
||||||
|
elif first_direction == 'anteroposterior':
|
||||||
|
ordering = (AnteroposteriorDirection, LateralDirection)
|
||||||
|
else:
|
||||||
|
return unit
|
||||||
|
|
||||||
|
if not integer_unit:
|
||||||
|
add_quadrant_standalone = address_config.get_property('{}.add_quadrant_standalone'.format(key),
|
||||||
|
language, country=country)
|
||||||
|
if add_quadrant_standalone:
|
||||||
|
unit = None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
last_num_type = None
|
||||||
|
for i, c in enumerate(ordering):
|
||||||
|
num_type, phrase, props = c.pick_phrase_and_type(unit, language, country=country)
|
||||||
|
whitespace_default = num_type == c.NUMERIC or last_num_type == c.NUMERIC
|
||||||
|
unit = c.combine_with_number(unit, phrase, num_type, props, whitespace_default=whitespace_default)
|
||||||
|
last_num_type = num_type
|
||||||
|
|
||||||
|
return unit
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def phrase(cls, unit, language, country=None, zone=None):
|
def phrase(cls, unit, language, country=None, zone=None):
|
||||||
if unit is not None:
|
if unit is not None:
|
||||||
key = 'units.alphanumeric' if zone is None else 'units.zones.{}'.format(zone)
|
key = 'units.alphanumeric' if zone is None else 'units.zones.{}'.format(zone)
|
||||||
|
|
||||||
|
direction_unit = None
|
||||||
add_direction = address_config.get_property('{}.add_direction'.format(key), language, country=country)
|
add_direction = address_config.get_property('{}.add_direction'.format(key), language, country=country)
|
||||||
if add_direction:
|
if add_direction:
|
||||||
unit = cls.add_direction(key, unit, language, country=country)
|
direction_unit = cls.add_direction(key, unit, language, country=country)
|
||||||
|
|
||||||
|
if direction_unit and direction_unit != unit:
|
||||||
|
unit = direction_unit
|
||||||
|
else:
|
||||||
|
add_quadrant = address_config.get_property('{}.add_quadrant'.format(key), language, country=country)
|
||||||
|
if add_quadrant:
|
||||||
|
unit = cls.add_quadrant(key, unit, language, country=country)
|
||||||
|
|
||||||
return cls.numeric_phrase(key, safe_decode(unit), language,
|
return cls.numeric_phrase(key, safe_decode(unit), language,
|
||||||
dictionaries=['unit_types_numbered'], country=country)
|
dictionaries=['unit_types_numbered'], country=country)
|
||||||
|
|||||||
Reference in New Issue
Block a user