Fixed cosmetic issues

This commit is contained in:
miku0
2023-07-31 02:39:04 +00:00
parent 67706cec4e
commit 2350018106

View File

@@ -19,39 +19,28 @@ from nominatim.tokenizer.sanitizers.config import SanitizerConfig
from nominatim.data.place_name import PlaceName from nominatim.data.place_name import PlaceName
KANJI_MAP = { KANJI_MAP = {
'': '0', ord(''): '0',
'': '1', ord(''): '1',
'': '2', ord(''): '2',
'': '3', ord(''): '3',
'': '4', ord(''): '4',
'': '5', ord(''): '5',
'': '6', ord(''): '6',
'': '7', ord(''): '7',
'': '8', ord(''): '8',
'': '9' ord(''): '9'
} }
def convert_kanji_sequence_to_number(sequence: str) -> str: def convert_kanji_sequence_to_number(sequence: str) -> str:
"""Converts Kanji numbers to Arabic numbers """Converts Kanji numbers to Arabic numbers
""" """
converted = '' converted = sequence.translate(KANJI_MAP)
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
return converted return converted
def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]: def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
#def create(config: SanitizerConfig) -> Callable[[ProcessInfo],None]:
"""Set up the sanitizer """Set up the sanitizer
""" """
return tag_japanese return tag_japanese
#return tag_japanese(config)
def reconbine_housenumber( def reconbine_housenumber(
new_address: List[PlaceName], new_address: List[PlaceName],
@@ -60,6 +49,11 @@ def reconbine_housenumber(
) -> List[PlaceName]: ) -> List[PlaceName]:
""" Recombine the tag of housenumber by using housenumber and blocknumber """ 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: if tmp_blocknumber and tmp_housenumber:
new_address.append( new_address.append(
PlaceName( PlaceName(
@@ -72,7 +66,7 @@ def reconbine_housenumber(
new_address.append( new_address.append(
PlaceName( PlaceName(
kind='housenumber', kind='housenumber',
name=f'{tmp_blocknumber}', name=tmp_blocknumber,
suffix='' suffix=''
) )
) )
@@ -80,7 +74,7 @@ def reconbine_housenumber(
new_address.append( new_address.append(
PlaceName( PlaceName(
kind='housenumber', kind='housenumber',
name=f'{tmp_housenumber}', name=tmp_housenumber,
suffix='' suffix=''
) )
) )
@@ -93,6 +87,11 @@ def reconbine_place(
) -> List[PlaceName]: ) -> List[PlaceName]:
""" Recombine the tag of place by using neighbourhood and quarter """ 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: if tmp_neighbourhood and tmp_quarter:
new_address.append( new_address.append(
PlaceName( PlaceName(
@@ -105,7 +104,7 @@ def reconbine_place(
new_address.append( new_address.append(
PlaceName( PlaceName(
kind='place', kind='place',
name=f'{tmp_neighbourhood}', name=tmp_neighbourhood,
suffix='' suffix=''
) )
) )
@@ -113,7 +112,7 @@ def reconbine_place(
new_address.append( new_address.append(
PlaceName( PlaceName(
kind='place', kind='place',
name=f'{tmp_quarter}', name=tmp_quarter,
suffix='' suffix=''
) )
) )
@@ -129,11 +128,7 @@ def tag_japanese(obj: ProcessInfo) -> None:
tmp_quarter = None tmp_quarter = None
new_address = [] new_address = []
for item in obj.names:
item.name = convert_kanji_sequence_to_number(item.name)
for item in obj.address: for item in obj.address:
item.name = convert_kanji_sequence_to_number(item.name)
if item.kind == 'housenumber': if item.kind == 'housenumber':
tmp_housenumber = item.name tmp_housenumber = item.name
elif item.kind == 'block_number': elif item.kind == 'block_number':
@@ -145,7 +140,7 @@ def tag_japanese(obj: ProcessInfo) -> None:
else: else:
new_address.append(item) new_address.append(item)
new_address = reconbine_housenumber(new_address,tmp_housenumber,tmp_blocknumber) new_address = reconbine_housenumber(new_address, tmp_housenumber, tmp_blocknumber)
new_address = reconbine_place(new_address,tmp_neighbourhood,tmp_quarter) new_address = reconbine_place(new_address, tmp_neighbourhood, tmp_quarter)
obj.address = [item for item in new_address if item.name is not None] obj.address = [item for item in new_address if item.name is not None]