]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tokenizer/sanitizers/strip_brace_terms.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / tokenizer / sanitizers / strip_brace_terms.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
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.
11 """
12
13 def create(_):
14     """ Create a name processing function that creates additional name variants
15         for bracket addendums.
16     """
17     def _process(obj):
18         """ Add variants for names that have a bracket extension.
19         """
20         if obj.names:
21             new_names = []
22             for name in (n for n in obj.names if '(' in n.name):
23                 new_name = name.name.split('(')[0].strip()
24                 if new_name:
25                     new_names.append(name.clone(name=new_name))
26
27             obj.names.extend(new_names)
28
29     return _process