[intersections] Allowing tags like name_1, etc. to make it into road name permutations for intersections

This commit is contained in:
Al
2016-08-19 13:12:02 -04:00
parent 0b2d3d965f
commit a7118b40a7

View File

@@ -2,6 +2,7 @@
import itertools import itertools
import os import os
import random import random
import re
import six import six
import sys import sys
import yaml import yaml
@@ -65,6 +66,8 @@ JAPANESE_ROMAJI = 'ja_rm'
ENGLISH = 'en' ENGLISH = 'en'
numbered_tag_regex = re.compile('_[\d]+$')
class OSMAddressFormatter(object): class OSMAddressFormatter(object):
aliases = Aliases( aliases = Aliases(
@@ -226,6 +229,15 @@ class OSMAddressFormatter(object):
max_floors = num_floors max_floors = num_floors
return max_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): def abbreviated_street(self, street, language):
''' '''
Street abbreviations Street abbreviations
@@ -1090,6 +1102,10 @@ class OSMAddressFormatter(object):
for tag in way: for tag in way:
tag = safe_decode(tag) tag = safe_decode(tag)
base_tag = tag.rsplit(six.u(':'), 1)[0] 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: if base_tag not in all_name_tags:
continue continue
lang = safe_decode(tag.rsplit(six.u(':'))[-1]) if six.u(':') in tag else None lang = safe_decode(tag.rsplit(six.u(':'))[-1]) if six.u(':') in tag else None