match_types for Google metadata

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-16 11:34:33 +02:00
parent 6e78da55b2
commit f2197d4b2a
2 changed files with 20 additions and 3 deletions

View File

@ -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)
}

View File

@ -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'])