]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tokenizer/sanitizers/split_name_list.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / tokenizer / sanitizers / split_name_list.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 Sanitizer that splits lists of names into their components.
9
10 Arguments:
11     delimiters: Define the set of characters to be used for
12                 splitting the list. (default: ',;')
13 """
14 from nominatim.tokenizer.sanitizers.helpers import create_split_regex
15
16 def create(func):
17     """ Create a name processing function that splits name values with
18         multiple values into their components.
19     """
20     regexp = create_split_regex(func)
21
22     def _process(obj):
23         if not obj.names:
24             return
25
26         new_names = []
27         for name in obj.names:
28             split_names = regexp.split(name.name)
29             if len(split_names) == 1:
30                 new_names.append(name)
31             else:
32                 new_names.extend(name.clone(name=n) for n in split_names if n)
33
34         obj.names = new_names
35
36     return _process