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
17 from nominatim.tokenizer.sanitizers.base import ProcessInfo
18 from nominatim.tokenizer.sanitizers.config import SanitizerConfig
19 from nominatim.data.place_name import PlaceName
21 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
22 #def create(config: SanitizerConfig) -> Callable[[ProcessInfo],None]:
23 """Set up the sanitizer
26 #return tag_japanese(config)
28 def convert_kanji_sequence_to_number(sequence: str) -> str:
29 """Converts Kanji numbers to Arabic numbers
47 current_number += kanji_map[char]
49 converted += current_number
52 converted += current_number
55 def reconbine_housenumber(
56 new_address: List[PlaceName],
57 tmp_housenumber: str | None,
58 tmp_blocknumber: str | None
60 """ Recombine the tag of housenumber by using housenumber and blocknumber
62 if tmp_blocknumber and tmp_housenumber:
66 name=f'{tmp_blocknumber}-{tmp_housenumber}',
74 name=f'{tmp_blocknumber}',
82 name=f'{tmp_housenumber}',
89 new_address: List[PlaceName],
90 tmp_neighbourhood: str | None,
91 tmp_quarter: str | None
93 """ Recombine the tag of place by using neighbourhood and quarter
95 if tmp_neighbourhood and tmp_quarter:
99 name=f'{tmp_quarter}{tmp_neighbourhood}',
103 elif tmp_neighbourhood:
107 name=f'{tmp_neighbourhood}',
115 name=f'{tmp_quarter}',
120 def tag_japanese(obj: ProcessInfo) -> None:
121 """Recombine kind of address
123 if obj.place.country_code != 'jp':
125 tmp_housenumber = None
126 tmp_blocknumber = None
127 tmp_neighbourhood = None
131 for item in obj.names:
132 item.name = convert_kanji_sequence_to_number(item.name)
134 for item in obj.address:
135 item.name = convert_kanji_sequence_to_number(item.name)
136 if item.kind == 'housenumber':
137 tmp_housenumber = item.name
138 elif item.kind == 'block_number':
139 tmp_blocknumber = item.name
140 elif item.kind == 'neighbourhood':
141 tmp_neighbourhood = item.name
142 elif item.kind == 'quarter':
143 tmp_quarter = item.name
145 new_address.append(item)
147 new_address = reconbine_housenumber(new_address,tmp_housenumber,tmp_blocknumber)
148 new_address = reconbine_place(new_address,tmp_neighbourhood,tmp_quarter)
150 obj.address = [item for item in new_address if item.name is not None]