X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/206ee8718864d623507a0ae69070478dec411e84..4774e45218bcfcef3390f820ad48b1b67b2bd0c4:/nominatim/tokenizer/sanitizers/clean_housenumbers.py?ds=sidebyside diff --git a/nominatim/tokenizer/sanitizers/clean_housenumbers.py b/nominatim/tokenizer/sanitizers/clean_housenumbers.py index 5b592bcf..b65880c3 100644 --- a/nominatim/tokenizer/sanitizers/clean_housenumbers.py +++ b/nominatim/tokenizer/sanitizers/clean_housenumbers.py @@ -6,13 +6,19 @@ # For a full list of authors see the git log. """ Sanitizer that cleans and normalizes housenumbers. + +Arguments: + delimiters: Define the set of characters to be used for + splitting a list of housenumbers into parts. (default: ',;') + """ -import re +from nominatim.tokenizer.sanitizers.helpers import create_split_regex class _HousenumberSanitizer: def __init__(self, config): - pass + self.kinds = config.get('filter-kind', ('housenumber', )) + self.split_regexp = create_split_regex(config) def __call__(self, obj): @@ -21,7 +27,7 @@ class _HousenumberSanitizer: new_address = [] for item in obj.address: - if item.kind in ('housenumber', 'streetnumber', 'conscriptionnumber'): + if item.kind in self.kinds: new_address.extend(item.clone(kind='housenumber', name=n) for n in self.sanitize(item.name)) else: # Don't touch other address items. @@ -36,13 +42,9 @@ class _HousenumberSanitizer: The function works as a generator that yields all valid housenumbers that can be created from the value. """ - for hnr in self._split_number(value): - yield from self._regularize(hnr) - - - def _split_number(self, hnr): - for part in re.split(r'[;,]', hnr): - yield part.strip() + for hnr in self.split_regexp.split(value): + if hnr: + yield from self._regularize(hnr) def _regularize(self, hnr):