]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tokenizer/sanitizers/strip_brace_terms.py
add unit tests for new sanatizer functions
[nominatim.git] / nominatim / tokenizer / sanitizers / strip_brace_terms.py
1 """
2 Sanitizer handling names with addendums in braces.
3 """
4
5 def create(_):
6     """ Create a name processing function that creates additional name variants
7         when a name has an addendum in brackets (e.g. "Halle (Saale)"). The
8         additional variant only contains the main name without the bracket part.
9     """
10     def _process(obj):
11         """ Add variants for names that have a bracket extension.
12         """
13         if obj.names:
14             new_names = []
15             for name in (n for n in obj.names if '(' in n.name):
16                 new_name = name.name.split('(')[0].strip()
17                 if new_name:
18                     new_names.append(name.clone(name=new_name))
19
20             obj.names.extend(new_names)
21
22     return _process