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
20 from nominatim.tokenizer.sanitizers.kanji_utils import convert_kanji_sequence_to_number
22 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
23 #def create(config: SanitizerConfig) -> Callable[[ProcessInfo],None]:
24 """Set up the sanitizer
27 #return tag_japanese(config)
29 def reconbine_housenumber(
30 new_address: List[PlaceName],
31 tmp_housenumber: Optional[str],
32 tmp_blocknumber: Optional[str]
34 """ Recombine the tag of housenumber by using housenumber and blocknumber
36 if tmp_blocknumber and tmp_housenumber:
40 name=f'{tmp_blocknumber}-{tmp_housenumber}',
48 name=f'{tmp_blocknumber}',
56 name=f'{tmp_housenumber}',
63 new_address: List[PlaceName],
64 tmp_neighbourhood: Optional[str],
65 tmp_quarter: Optional[str]
67 """ Recombine the tag of place by using neighbourhood and quarter
69 if tmp_neighbourhood and tmp_quarter:
73 name=f'{tmp_quarter}{tmp_neighbourhood}',
77 elif tmp_neighbourhood:
81 name=f'{tmp_neighbourhood}',
89 name=f'{tmp_quarter}',
94 def tag_japanese(obj: ProcessInfo) -> None:
95 """Recombine kind of address
97 if obj.place.country_code != 'jp':
99 tmp_housenumber = None
100 tmp_blocknumber = None
101 tmp_neighbourhood = None
105 for item in obj.names:
106 item.name = convert_kanji_sequence_to_number(item.name)
108 for item in obj.address:
109 item.name = convert_kanji_sequence_to_number(item.name)
110 if item.kind == 'housenumber':
111 tmp_housenumber = item.name
112 elif item.kind == 'block_number':
113 tmp_blocknumber = item.name
114 elif item.kind == 'neighbourhood':
115 tmp_neighbourhood = item.name
116 elif item.kind == 'quarter':
117 tmp_quarter = item.name
119 new_address.append(item)
121 new_address = reconbine_housenumber(new_address,tmp_housenumber,tmp_blocknumber)
122 new_address = reconbine_place(new_address,tmp_neighbourhood,tmp_quarter)
124 obj.address = [item for item in new_address if item.name is not None]