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
37 converted = sequence.translate(KANJI_MAP)
40 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
41 """Set up the sanitizer
45 def reconbine_housenumber(
46 new_address: List[PlaceName],
47 tmp_housenumber: Optional[str],
48 tmp_blocknumber: Optional[str]
50 """ Recombine the tag of housenumber by using housenumber and blocknumber
53 tmp_blocknumber = convert_kanji_sequence_to_number(tmp_blocknumber)
55 tmp_housenumber = convert_kanji_sequence_to_number(tmp_housenumber)
57 if tmp_blocknumber and tmp_housenumber:
61 name=f'{tmp_blocknumber}-{tmp_housenumber}',
84 new_address: List[PlaceName],
85 tmp_neighbourhood: Optional[str],
86 tmp_quarter: Optional[str]
88 """ Recombine the tag of place by using neighbourhood and quarter
91 tmp_neighbourhood = convert_kanji_sequence_to_number(tmp_neighbourhood)
93 tmp_quarter = convert_kanji_sequence_to_number(tmp_quarter)
95 if tmp_neighbourhood and tmp_quarter:
99 name=f'{tmp_quarter}{tmp_neighbourhood}',
103 elif tmp_neighbourhood:
107 name=tmp_neighbourhood,
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.address:
132 if item.kind == 'housenumber':
133 tmp_housenumber = item.name
134 elif item.kind == 'block_number':
135 tmp_blocknumber = item.name
136 elif item.kind == 'neighbourhood':
137 tmp_neighbourhood = item.name
138 elif item.kind == 'quarter':
139 tmp_quarter = item.name
141 new_address.append(item)
143 new_address = reconbine_housenumber(new_address, tmp_housenumber, tmp_blocknumber)
144 new_address = reconbine_place(new_address, tmp_neighbourhood, tmp_quarter)
146 obj.address = [item for item in new_address if item.name is not None]