1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 This sanitizer maps OSM data to Japanese block addresses.
9 It replaces blocknumber and housenumber with housenumber,
10 and quarter and neighbourhood with place.
14 from typing import Callable
15 from typing import List, Optional
17 from nominatim.tokenizer.sanitizers.base import ProcessInfo
18 from nominatim.tokenizer.sanitizers.config import SanitizerConfig
19 from nominatim.data.place_name import PlaceName
34 def convert_kanji_sequence_to_number(sequence: str) -> str:
35 """Converts Kanji numbers to Arabic numbers
41 current_number += KANJI_MAP[char]
43 converted += current_number
46 converted += current_number
49 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
50 #def create(config: SanitizerConfig) -> Callable[[ProcessInfo],None]:
51 """Set up the sanitizer
54 #return tag_japanese(config)
56 def reconbine_housenumber(
57 new_address: List[PlaceName],
58 tmp_housenumber: Optional[str],
59 tmp_blocknumber: Optional[str]
61 """ Recombine the tag of housenumber by using housenumber and blocknumber
63 if tmp_blocknumber and tmp_housenumber:
67 name=f'{tmp_blocknumber}-{tmp_housenumber}',
75 name=f'{tmp_blocknumber}',
83 name=f'{tmp_housenumber}',
90 new_address: List[PlaceName],
91 tmp_neighbourhood: Optional[str],
92 tmp_quarter: Optional[str]
94 """ Recombine the tag of place by using neighbourhood and quarter
96 if tmp_neighbourhood and tmp_quarter:
100 name=f'{tmp_quarter}{tmp_neighbourhood}',
104 elif tmp_neighbourhood:
108 name=f'{tmp_neighbourhood}',
116 name=f'{tmp_quarter}',
121 def tag_japanese(obj: ProcessInfo) -> None:
122 """Recombine kind of address
124 if obj.place.country_code != 'jp':
126 tmp_housenumber = None
127 tmp_blocknumber = None
128 tmp_neighbourhood = None
132 for item in obj.names:
133 item.name = convert_kanji_sequence_to_number(item.name)
135 for item in obj.address:
136 item.name = convert_kanji_sequence_to_number(item.name)
137 if item.kind == 'housenumber':
138 tmp_housenumber = item.name
139 elif item.kind == 'block_number':
140 tmp_blocknumber = item.name
141 elif item.kind == 'neighbourhood':
142 tmp_neighbourhood = item.name
143 elif item.kind == 'quarter':
144 tmp_quarter = item.name
146 new_address.append(item)
148 new_address = reconbine_housenumber(new_address,tmp_housenumber,tmp_blocknumber)
149 new_address = reconbine_place(new_address,tmp_neighbourhood,tmp_quarter)
151 obj.address = [item for item in new_address if item.name is not None]