1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 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 .base import ProcessInfo
 
  15 from .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                 if ')' in name.name and not name.name.endswith(')'):
 
  30                 new_name = name.name.split('(')[0].strip()
 
  32                     new_names.append(name.clone(name=new_name))
 
  34             obj.names.extend(new_names)