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
21 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
22 """Set up the sanitizer
26 def reconbine_housenumber(
27 new_address: List[PlaceName],
28 tmp_housenumber: Optional[str],
29 tmp_blocknumber: Optional[str]
31 """ Recombine the tag of housenumber by using housenumber and blocknumber
33 if tmp_blocknumber and tmp_housenumber:
37 name=f'{tmp_blocknumber}-{tmp_housenumber}',
60 new_address: List[PlaceName],
61 tmp_neighbourhood: Optional[str],
62 tmp_quarter: Optional[str]
64 """ Recombine the tag of place by using neighbourhood and quarter
66 if tmp_neighbourhood and tmp_quarter:
70 name=f'{tmp_quarter}{tmp_neighbourhood}',
74 elif tmp_neighbourhood:
78 name=tmp_neighbourhood,
91 def tag_japanese(obj: ProcessInfo) -> None:
92 """Recombine kind of address
94 if obj.place.country_code != 'jp':
96 tmp_housenumber = None
97 tmp_blocknumber = None
98 tmp_neighbourhood = None
102 for item in obj.address:
103 if item.kind == 'housenumber':
104 tmp_housenumber = item.name
105 elif item.kind == 'block_number':
106 tmp_blocknumber = item.name
107 elif item.kind == 'neighbourhood':
108 tmp_neighbourhood = item.name
109 elif item.kind == 'quarter':
110 tmp_quarter = item.name
112 new_address.append(item)
114 new_address = reconbine_housenumber(new_address, tmp_housenumber, tmp_blocknumber)
115 new_address = reconbine_place(new_address, tmp_neighbourhood, tmp_quarter)
117 obj.address = [item for item in new_address if item.name is not None]