1 # SPDX-License-Identifier: GPL-2.0-only
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 Sanitizer that cleans and normalizes housenumbers.
12 class _HousenumberSanitizer:
14 def __init__(self, config):
18 def __call__(self, obj):
23 for item in obj.address:
24 if item.kind in ('housenumber', 'streetnumber', 'conscriptionnumber'):
25 new_address.extend(item.clone(kind='housenumber', name=n) for n in self.sanitize(item.name))
27 # Don't touch other address items.
28 new_address.append(item)
30 obj.address = new_address
33 def sanitize(self, value):
34 """ Extract housenumbers in a regularized format from an OSM value.
36 The function works as a generator that yields all valid housenumbers
37 that can be created from the value.
39 for hnr in self._split_number(value):
40 yield from self._regularize(hnr)
43 def _split_number(self, hnr):
44 for part in re.split(r'[;,]', hnr):
48 def _regularize(self, hnr):
53 """ Create a housenumber processing function.
56 return _HousenumberSanitizer(config)