match_types for Mapbox metadata

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-16 12:11:40 +02:00
parent 0a92ae1445
commit 080de34163
2 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,17 @@ TYPE_POINT = 'Point'
EMPTY_RESPONSE = [[], {}]
MATCH_TYPE_BY_MATCH_LEVEL = {
'poi': 'point_of_interest',
'poi.landmark': 'point_of_interest',
'place': 'point_of_interest',
'country': 'country',
'region': 'state',
'locality': 'locality',
'district': 'district',
'address': 'street'
}
class MapboxGeocoder(Traceable):
'''
@ -80,9 +91,12 @@ class MapboxGeocoder(Traceable):
else:
precision = PRECISION_PRECISE
match_types = [MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None)
for match_level in result['place_type']]
return {
'relevance': self._normalize_relevance(float(result['relevance'])),
'precision': precision
'precision': precision,
'match_types': filter(None, match_types)
}
def _normalize_relevance(self, relevance):

View File

@ -92,9 +92,9 @@ class TestStreetFunctionsSetUp(TestCase):
MAPBOX_METADATAS = {
'Plaza España, Barcelona':
{'relevance': 0.666, 'precision': 'precise'},
{'relevance': 0.666, 'precision': 'precise', 'match_types': ['point_of_interest']},
'Santiago Rusiñol 123, Valladolid':
{'relevance': 0.666, 'precision': 'precise'} # TODO: wrong
{'relevance': 0.666, 'precision': 'precise', 'match_types': ['point_of_interest']} # TODO: wrong
}
METADATAS = {