X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/8171fe4571a57bf8e5b2a8f676989e973897e2e7..fa44f7bcb308bfe51cc68ad15c2e4574f2182a09:/nominatim/tokenizer/sanitizers/strip_brace_terms.py?ds=sidebyside diff --git a/nominatim/tokenizer/sanitizers/strip_brace_terms.py b/nominatim/tokenizer/sanitizers/strip_brace_terms.py index 4423d305..119d5693 100644 --- a/nominatim/tokenizer/sanitizers/strip_brace_terms.py +++ b/nominatim/tokenizer/sanitizers/strip_brace_terms.py @@ -1,22 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ -Sanitizer handling names with addendums in braces. +This sanitizer creates additional name variants for names that have +addendums in brackets (e.g. "Halle (Saale)"). The additional variant contains +only the main name part with the bracket part removed. """ +from typing import Callable -def create(_): +from nominatim.tokenizer.sanitizers.base import ProcessInfo +from nominatim.tokenizer.sanitizers.config import SanitizerConfig + + +def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]: """ Create a name processing function that creates additional name variants - when a name has an addendum in brackets (e.g. "Halle (Saale)"). The - additional variant only contains the main name without the bracket part. + for bracket addendums. """ - def _process(obj): + def _process(obj: ProcessInfo) -> None: """ Add variants for names that have a bracket extension. """ - new_names = [] if obj.names: + new_names = [] for name in (n for n in obj.names if '(' in n.name): new_name = name.name.split('(')[0].strip() if new_name: new_names.append(name.clone(name=new_name)) - obj.names.extend(new_names) + obj.names.extend(new_names) return _process