[intersections] Adding places to intersection template, intersection phrase generator
This commit is contained in:
@@ -528,6 +528,9 @@ cross_streets:
|
|||||||
corner_of: &corner_of
|
corner_of: &corner_of
|
||||||
canonical: corner of
|
canonical: corner of
|
||||||
|
|
||||||
|
at_the_corner_of: &at_the_corner_of
|
||||||
|
canonical: at the corner of
|
||||||
|
|
||||||
intersection:
|
intersection:
|
||||||
default: *and
|
default: *and
|
||||||
probability: 0.7
|
probability: 0.7
|
||||||
@@ -535,7 +538,9 @@ cross_streets:
|
|||||||
- alternative: *at
|
- alternative: *at
|
||||||
probability: 0.15
|
probability: 0.15
|
||||||
- alternative: *corner_of
|
- alternative: *corner_of
|
||||||
probability: 0.15
|
probability: 0.1
|
||||||
|
- alternative: *at_the_corner_of
|
||||||
|
probability: 0.05
|
||||||
|
|
||||||
# 26th betw 5th Ave and 6th Ave
|
# 26th betw 5th Ave and 6th Ave
|
||||||
between:
|
between:
|
||||||
|
|||||||
@@ -344,6 +344,9 @@ cross_streets:
|
|||||||
corner_of: &esquina_de
|
corner_of: &esquina_de
|
||||||
canonical: esquina de
|
canonical: esquina de
|
||||||
abbreviated: esq de
|
abbreviated: esq de
|
||||||
|
at_the_corner_of: &at_the_corner_of
|
||||||
|
canonical: en la esquina de
|
||||||
|
abbreviated: en la esq de
|
||||||
corner: &esquina
|
corner: &esquina
|
||||||
canonical: esquina
|
canonical: esquina
|
||||||
abbreviated: esq
|
abbreviated: esq
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
&
|
||||||
and
|
and
|
||||||
|
@
|
||||||
at
|
at
|
||||||
|
at the corner of
|
||||||
corner of
|
corner of
|
||||||
between|betw|btwn|btw|btween|b / t
|
between|betw|btwn|btw|btween|b / t
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
&
|
||||||
y
|
y
|
||||||
en
|
en
|
||||||
con
|
con
|
||||||
esquina|esq
|
esquina|esq
|
||||||
|
en la esquina de|en la esq de
|
||||||
esquina de|esq de
|
esquina de|esq de
|
||||||
entre|e /
|
entre|entre /|e /
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
category_template = '{{{category}}} {{{near}}} {{{place}}}'
|
category_template = '{{{category}}} {{{near}}} {{{place}}}'
|
||||||
chain_template = '{{{house}}} {{{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_address_parts = [HOUSE, HOUSE_NUMBER, ROAD]
|
||||||
template_admin_parts = [CITY, STATE, COUNTRY]
|
template_admin_parts = [CITY, STATE, COUNTRY]
|
||||||
@@ -746,7 +746,8 @@ class AddressFormatter(object):
|
|||||||
|
|
||||||
return self.render_template(self.chain_template, components, tagged=tag_components)
|
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:
|
if tag_components:
|
||||||
components = {'road1': self.tagged_tokens(intersection_query.road1, self.ROAD),
|
components = {'road1': self.tagged_tokens(intersection_query.road1, self.ROAD),
|
||||||
'intersection': self.tagged_tokens(intersection_query.intersection_phrase, self.INTERSECTION),
|
'intersection': self.tagged_tokens(intersection_query.intersection_phrase, self.INTERSECTION),
|
||||||
@@ -756,6 +757,13 @@ class AddressFormatter(object):
|
|||||||
components = {'road1': intersection_query.road1,
|
components = {'road1': intersection_query.road1,
|
||||||
'intersection': intersection_query.intersection_phrase,
|
'intersection': intersection_query.intersection_phrase,
|
||||||
'road2': intersection_query.road2}
|
'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)
|
return self.render_template(self.intersection_template, components, tagged=tag_components)
|
||||||
|
|
||||||
def format_address(self, components, country, language,
|
def format_address(self, components, country, language,
|
||||||
|
|||||||
0
scripts/geodata/intersections/__init__.py
Normal file
0
scripts/geodata/intersections/__init__.py
Normal file
18
scripts/geodata/intersections/query.py
Normal file
18
scripts/geodata/intersections/query.py
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user