diff --git a/resources/addresses/en.yaml b/resources/addresses/en.yaml index a877eab9..f3fbc476 100644 --- a/resources/addresses/en.yaml +++ b/resources/addresses/en.yaml @@ -528,6 +528,9 @@ cross_streets: corner_of: &corner_of canonical: corner of + at_the_corner_of: &at_the_corner_of + canonical: at the corner of + intersection: default: *and probability: 0.7 @@ -535,7 +538,9 @@ cross_streets: - alternative: *at probability: 0.15 - alternative: *corner_of - probability: 0.15 + probability: 0.1 + - alternative: *at_the_corner_of + probability: 0.05 # 26th betw 5th Ave and 6th Ave between: diff --git a/resources/addresses/es.yaml b/resources/addresses/es.yaml index e157291c..11e7c7df 100644 --- a/resources/addresses/es.yaml +++ b/resources/addresses/es.yaml @@ -344,6 +344,9 @@ cross_streets: corner_of: &esquina_de canonical: esquina de abbreviated: esq de + at_the_corner_of: &at_the_corner_of + canonical: en la esquina de + abbreviated: en la esq de corner: &esquina canonical: esquina abbreviated: esq diff --git a/resources/dictionaries/en/cross_streets.txt b/resources/dictionaries/en/cross_streets.txt index 3a0587a7..f3e89245 100644 --- a/resources/dictionaries/en/cross_streets.txt +++ b/resources/dictionaries/en/cross_streets.txt @@ -1,4 +1,7 @@ +& and +@ at +at the corner of corner of between|betw|btwn|btw|btween|b / t \ No newline at end of file diff --git a/resources/dictionaries/es/cross_streets.txt b/resources/dictionaries/es/cross_streets.txt index 9b3ae148..722ea258 100644 --- a/resources/dictionaries/es/cross_streets.txt +++ b/resources/dictionaries/es/cross_streets.txt @@ -1,6 +1,8 @@ +& y en con esquina|esq +en la esquina de|en la esq de esquina de|esq de -entre|e / \ No newline at end of file +entre|entre /|e / diff --git a/scripts/geodata/address_formatting/formatter.py b/scripts/geodata/address_formatting/formatter.py index d12a56a9..05703124 100644 --- a/scripts/geodata/address_formatting/formatter.py +++ b/scripts/geodata/address_formatting/formatter.py @@ -154,7 +154,7 @@ class AddressFormatter(object): category_template = '{{{category}}} {{{near}}} {{{place}}}' chain_template = '{{{house}}} {{{near}}} {{{place}}}' - intersection_template = '{{{road1}}} {{{intersection}}} {{{road2}}}' + intersection_template = '{{{road1}}} {{{intersection}}} {{{road2}}} {{{place}}}' template_address_parts = [HOUSE, HOUSE_NUMBER, ROAD] template_admin_parts = [CITY, STATE, COUNTRY] @@ -746,7 +746,8 @@ class AddressFormatter(object): return self.render_template(self.chain_template, components, tagged=tag_components) - def format_intersection(self, intersection_query, tag_components=True): + def format_intersection(self, intersection_query, place_components, country, language, tag_components=True): + components = {} if tag_components: components = {'road1': self.tagged_tokens(intersection_query.road1, self.ROAD), 'intersection': self.tagged_tokens(intersection_query.intersection_phrase, self.INTERSECTION), @@ -756,6 +757,13 @@ class AddressFormatter(object): components = {'road1': intersection_query.road1, 'intersection': intersection_query.intersection_phrase, 'road2': intersection_query.road2} + + if place_components: + place_formatted = self.format_address(place_components, country, language=language, + minimal_only=False, tag_components=tag_components) + + if place_formatted: + components['place'] = place_formatted return self.render_template(self.intersection_template, components, tagged=tag_components) def format_address(self, components, country, language, diff --git a/scripts/geodata/intersections/__init__.py b/scripts/geodata/intersections/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/geodata/intersections/query.py b/scripts/geodata/intersections/query.py new file mode 100644 index 00000000..ff2e09bb --- /dev/null +++ b/scripts/geodata/intersections/query.py @@ -0,0 +1,18 @@ +from collections import namedtuple + +from geodata.addresses.config import address_config +from geodata.math.sampling import weighted_choice + +IntersectionQuery = namedtuple('IntersectionQuery', 'road1, intersection_phrase, road2') + +NULL_INTERSECTION_QUERY = IntersectionQuery(None, None, None) + + +class Intersection(object): + @classmethod + def phrase(cls, language, country=None): + values, probs = address_config.alternative_probabilities('cross_streets.intersection', language, country=country) + if not values: + return None + phrase, props = weighted_choice(values, probs) + return phrase