from nominatim.data.place_name import PlaceName
KANJI_MAP = {
- '零': '0',
- '一': '1',
- '二': '2',
- '三': '3',
- '四': '4',
- '五': '5',
- '六': '6',
- '七': '7',
- '八': '8',
- '九': '9'
+ ord('零'): '0',
+ ord('一'): '1',
+ ord('二'): '2',
+ ord('三'): '3',
+ ord('四'): '4',
+ ord('五'): '5',
+ ord('六'): '6',
+ ord('七'): '7',
+ ord('八'): '8',
+ ord('九'): '9'
}
def convert_kanji_sequence_to_number(sequence: str) -> str:
"""Converts Kanji numbers to Arabic numbers
"""
- converted = ''
- current_number = ''
- for char in sequence:
- if char in KANJI_MAP:
- current_number += KANJI_MAP[char]
- else:
- converted += current_number
- current_number = ''
- converted += char
- converted += current_number
+ converted = sequence.translate(KANJI_MAP)
return converted
def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
-#def create(config: SanitizerConfig) -> Callable[[ProcessInfo],None]:
"""Set up the sanitizer
"""
return tag_japanese
- #return tag_japanese(config)
def reconbine_housenumber(
new_address: List[PlaceName],
) -> List[PlaceName]:
""" Recombine the tag of housenumber by using housenumber and blocknumber
"""
+ if tmp_blocknumber:
+ tmp_blocknumber = convert_kanji_sequence_to_number(tmp_blocknumber)
+ if tmp_housenumber:
+ tmp_housenumber = convert_kanji_sequence_to_number(tmp_housenumber)
+
if tmp_blocknumber and tmp_housenumber:
new_address.append(
PlaceName(
new_address.append(
PlaceName(
kind='housenumber',
- name=f'{tmp_blocknumber}',
+ name=tmp_blocknumber,
suffix=''
)
)
new_address.append(
PlaceName(
kind='housenumber',
- name=f'{tmp_housenumber}',
+ name=tmp_housenumber,
suffix=''
)
)
) -> List[PlaceName]:
""" Recombine the tag of place by using neighbourhood and quarter
"""
+ if tmp_neighbourhood:
+ tmp_neighbourhood = convert_kanji_sequence_to_number(tmp_neighbourhood)
+ if tmp_quarter:
+ tmp_quarter = convert_kanji_sequence_to_number(tmp_quarter)
+
if tmp_neighbourhood and tmp_quarter:
new_address.append(
PlaceName(
new_address.append(
PlaceName(
kind='place',
- name=f'{tmp_neighbourhood}',
+ name=tmp_neighbourhood,
suffix=''
)
)
new_address.append(
PlaceName(
kind='place',
- name=f'{tmp_quarter}',
+ name=tmp_quarter,
suffix=''
)
)
tmp_quarter = None
new_address = []
- for item in obj.names:
- item.name = convert_kanji_sequence_to_number(item.name)
-
for item in obj.address:
- item.name = convert_kanji_sequence_to_number(item.name)
if item.kind == 'housenumber':
tmp_housenumber = item.name
elif item.kind == 'block_number':
else:
new_address.append(item)
- new_address = reconbine_housenumber(new_address,tmp_housenumber,tmp_blocknumber)
- new_address = reconbine_place(new_address,tmp_neighbourhood,tmp_quarter)
+ new_address = reconbine_housenumber(new_address, tmp_housenumber, tmp_blocknumber)
+ new_address = reconbine_place(new_address, tmp_neighbourhood, tmp_quarter)
obj.address = [item for item in new_address if item.name is not None]