From 0a92ae14452331fc0a3fee960e06a2daecc8aee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Mon, 16 Jul 2018 12:01:55 +0200 Subject: [PATCH] match_types for TomTom metadata --- .../cartodb_services/tomtom/geocoder.py | 11 ++++++++++- test/integration/test_street_functions.py | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py index 42970f8..09ed69d 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/tomtom/geocoder.py @@ -24,6 +24,13 @@ EMPTY_RESPONSE = [[], {}] SCORE_NORMALIZATION_FACTOR = 0.15 PRECISION_SCORE_THRESHOLD = 0.5 +MATCH_TYPE_BY_MATCH_LEVEL = { + 'POI': 'point_of_interest', + 'Street': 'street', + 'Address Range': 'street', + 'Cross Street': 'intersection', + 'Point Address': 'street_number' +} class TomTomGeocoder(Traceable): ''' @@ -136,9 +143,11 @@ class TomTomGeocoder(Traceable): def _extract_metadata_from_result(self, result): score = self._normalize_score(result['score']) + match_type = MATCH_TYPE_BY_MATCH_LEVEL.get(result['type'], None) return { 'relevance': score, - 'precision': self._precision_from_score(score) + 'precision': self._precision_from_score(score), + 'match_types': [match_type] if match_type else [] } def _normalize_score(self, score): diff --git a/test/integration/test_street_functions.py b/test/integration/test_street_functions.py index bf7672e..1c05058 100644 --- a/test/integration/test_street_functions.py +++ b/test/integration/test_street_functions.py @@ -85,9 +85,9 @@ class TestStreetFunctionsSetUp(TestCase): TOMTOM_METADATAS = { 'Plaza España, Barcelona': - {'relevance': 0.85, 'precision': 'precise'}, + {'relevance': 0.85, 'precision': 'precise', 'match_types': ['street']}, 'Santiago Rusiñol 123, Valladolid': - {'relevance': 0.448283494533, 'precision': 'interpolated'} + {'relevance': 0.448283494533, 'precision': 'interpolated', 'match_types': ['street']} } MAPBOX_METADATAS = {