]> git.openstreetmap.org Git - nominatim.git/commitdiff
Fixed cosmetic issues
authormiku0 <miku.f.810129@gmail.com>
Mon, 31 Jul 2023 02:39:04 +0000 (02:39 +0000)
committermiku0 <miku.f.810129@gmail.com>
Mon, 31 Jul 2023 02:39:04 +0000 (02:39 +0000)
nominatim/tokenizer/sanitizers/tag_japanese.py

index 723a6dfaa27bca7b53854ec01504ff5d23d5a39b..46296456a978245d3dc3d2a373d664af6ec5e4d4 100644 (file)
@@ -19,39 +19,28 @@ from nominatim.tokenizer.sanitizers.config import SanitizerConfig
 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],
@@ -60,6 +49,11 @@ def reconbine_housenumber(
 ) -> 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(
@@ -72,7 +66,7 @@ def reconbine_housenumber(
         new_address.append(
             PlaceName(
                 kind='housenumber',
-                name=f'{tmp_blocknumber}',
+                name=tmp_blocknumber,
                 suffix=''
             )
         )
@@ -80,7 +74,7 @@ def reconbine_housenumber(
         new_address.append(
             PlaceName(
                 kind='housenumber',
-                name=f'{tmp_housenumber}',
+                name=tmp_housenumber,
                 suffix=''
             )
         )
@@ -93,6 +87,11 @@ def reconbine_place(
 ) -> 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(
@@ -105,7 +104,7 @@ def reconbine_place(
         new_address.append(
             PlaceName(
                 kind='place',
-                name=f'{tmp_neighbourhood}',
+                name=tmp_neighbourhood,
                 suffix=''
             )
         )
@@ -113,7 +112,7 @@ def reconbine_place(
         new_address.append(
             PlaceName(
                 kind='place',
-                name=f'{tmp_quarter}',
+                name=tmp_quarter,
                 suffix=''
             )
         )
@@ -129,11 +128,7 @@ def tag_japanese(obj: ProcessInfo) -> None:
     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':
@@ -145,7 +140,7 @@ def tag_japanese(obj: ProcessInfo) -> None:
         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]