From a7118b40a780a83f566a6b419273b63a78790c5b Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 19 Aug 2016 13:12:02 -0400 Subject: [PATCH] [intersections] Allowing tags like name_1, etc. to make it into road name permutations for intersections --- scripts/geodata/osm/formatter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/geodata/osm/formatter.py b/scripts/geodata/osm/formatter.py index 6b8bd648..00a94313 100644 --- a/scripts/geodata/osm/formatter.py +++ b/scripts/geodata/osm/formatter.py @@ -2,6 +2,7 @@ import itertools import os import random +import re import six import sys import yaml @@ -65,6 +66,8 @@ JAPANESE_ROMAJI = 'ja_rm' ENGLISH = 'en' +numbered_tag_regex = re.compile('_[\d]+$') + class OSMAddressFormatter(object): aliases = Aliases( @@ -226,6 +229,15 @@ class OSMAddressFormatter(object): max_floors = num_floors return max_floors + def replace_numbered_tag(self, tag): + ''' + If a tag is numbered like name_1, name_2, etc. replace it with name + ''' + match = numbered_tag_regex.search(tag) + if not match: + return None + return tag[:match.start()] + def abbreviated_street(self, street, language): ''' Street abbreviations @@ -1090,6 +1102,10 @@ class OSMAddressFormatter(object): for tag in way: tag = safe_decode(tag) base_tag = tag.rsplit(six.u(':'), 1)[0] + + normalized_tag = self.replace_numbered_tag(base_tag) + if normalized_tag: + base_tag = normalized_tag if base_tag not in all_name_tags: continue lang = safe_decode(tag.rsplit(six.u(':'))[-1]) if six.u(':') in tag else None