match_types for Google metadata
This commit is contained in:
parent
6e78da55b2
commit
f2197d4b2a
@ -23,6 +23,18 @@ PRECISION_BY_LOCATION_TYPE = {
|
||||
'RANGE_INTERPOLATED': PRECISION_INTERPOLATED,
|
||||
'APPROXIMATE': PRECISION_INTERPOLATED
|
||||
}
|
||||
MATCH_TYPE_BY_MATCH_LEVEL = {
|
||||
'point_of_interest': 'point_of_interest',
|
||||
'country': 'country',
|
||||
'administrative_area_level_1': 'state',
|
||||
'administrative_area_level_2': 'county',
|
||||
'locality': 'locality',
|
||||
'sublocality': 'district',
|
||||
'street_address': 'street',
|
||||
'intersection': 'intersection',
|
||||
'street_number': 'street_number',
|
||||
'postal_code': 'postal_code'
|
||||
}
|
||||
|
||||
|
||||
class GoogleMapsGeocoder():
|
||||
@ -70,9 +82,12 @@ class GoogleMapsGeocoder():
|
||||
base_relevance = RELEVANCE_BY_LOCATION_TYPE[location_type]
|
||||
partial_match = result.get('partial_match', False)
|
||||
partial_factor = PARTIAL_FACTOR if partial_match else 1
|
||||
match_types = [MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None)
|
||||
for match_level in result['types']]
|
||||
return {
|
||||
'relevance': base_relevance * partial_factor,
|
||||
'precision': PRECISION_BY_LOCATION_TYPE[location_type]
|
||||
'precision': PRECISION_BY_LOCATION_TYPE[location_type],
|
||||
'match_types': filter(None, match_types)
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,9 +71,9 @@ class TestStreetFunctionsSetUp(TestCase):
|
||||
|
||||
GOOGLE_METADATAS = {
|
||||
'Plaza España, Barcelona':
|
||||
{'relevance': 0.9, 'precision': 'precise'},
|
||||
{'relevance': 0.9, 'precision': 'precise', 'match_types': ['point_of_interest']},
|
||||
'Santiago Rusiñol 123, Valladolid':
|
||||
{'relevance': 0.56, 'precision': 'interpolated'}
|
||||
{'relevance': 0.56, 'precision': 'interpolated', 'match_types': ['locality']}
|
||||
}
|
||||
|
||||
HERE_METADATAS = {
|
||||
@ -408,3 +408,5 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
||||
'{} not close to {}'.format(relevance, expected_relevance))
|
||||
|
||||
assert_equal(metadata['precision'], expected['precision'])
|
||||
|
||||
assert_equal(metadata['match_types'], expected['match_types'])
|
||||
|
Loading…
Reference in New Issue
Block a user