Nominatim/nominatim/tokenizer/sanitizers/strip_brace_terms.py
2021-10-01 12:27:24 +02:00

23 lines
749 B
Python

"""
Sanitizer handling names with addendums in braces.
"""
def create(_):
""" 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.
"""
def _process(obj):
""" Add variants for names that have a bracket extension.
"""
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)
return _process