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 This sanitizer creates additional name variants for names that have
9 addendums in brackets (e.g. "Halle (Saale)"). The additional variant contains
10 only the main name part with the bracket part removed.
12 from typing import Callable
14 from nominatim.tokenizer.sanitizers.base import ProcessInfo
15 from nominatim.tokenizer.sanitizers.config import SanitizerConfig
18 def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
19 """ Create a name processing function that creates additional name variants
20 for bracket addendums.
22 def _process(obj: ProcessInfo) -> None:
23 """ Add variants for names that have a bracket extension.
27 for name in (n for n in obj.names if '(' in n.name):
28 new_name = name.name.split('(')[0].strip()
30 new_names.append(name.clone(name=new_name))
32 obj.names.extend(new_names)