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 Sanitizer that splits lists of names into their components.
11 delimiters: Define the set of characters to be used for
12 splitting the list. (default: `,;`)
16 from nominatim.errors import UsageError
19 """ Create a name processing function that splits name values with
20 multiple values into their components.
22 delimiter_set = set(func.get('delimiters', ',;'))
24 raise UsageError("Set of delimiters in split-name-list sanitizer is empty.")
26 regexp = re.compile('\\s*[{}]\\s*'.format(''.join('\\' + d for d in delimiter_set)))
33 for name in obj.names:
34 split_names = regexp.split(name.name)
35 if len(split_names) == 1:
36 new_names.append(name)
38 new_names.extend(name.clone(name=n) for n in split_names if n)