1from collections import namedtuple
2
3from geodata.addresses.config import address_config
4from geodata.math.sampling import weighted_choice
5
6IntersectionQuery = namedtuple('IntersectionQuery', 'road1, intersection_phrase, road2')
7
8NULL_INTERSECTION_QUERY = IntersectionQuery(None, None, None)
9
10
11class Intersection(object):
12    @classmethod
13    def phrase(cls, language, country=None):
14        values, probs = address_config.alternative_probabilities('cross_streets.intersection', language, country=country)
15        if not values:
16            return None
17        phrase, props = weighted_choice(values, probs)
18        return phrase
19