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 Tests for the sanitizer that handles braced suffixes.
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.indexer.place_info import PlaceInfo
15 def run_sanitizer_on(**kwargs):
16 place = PlaceInfo({'name': kwargs})
17 name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}]).process_names(place)
19 return sorted([(p.name, p.kind, p.suffix) for p in name])
23 assert run_sanitizer_on(name='foo', ref='23') == [('23', 'ref', None),
24 ('foo', 'name', None)]
27 def test_simple_braces():
28 assert run_sanitizer_on(name='Halle (Saale)', ref='3')\
29 == [('3', 'ref', None), ('Halle', 'name', None), ('Halle (Saale)', 'name', None)]
30 assert run_sanitizer_on(name='ack ( bar')\
31 == [('ack', 'name', None), ('ack ( bar', 'name', None)]
34 def test_only_braces():
35 assert run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
38 def test_double_braces():
39 assert run_sanitizer_on(name='a((b))') == [('a', 'name', None),
40 ('a((b))', 'name', None)]
41 assert run_sanitizer_on(name='a (b) (c)') == [('a', 'name', None),
42 ('a (b) (c)', 'name', None)]
46 place = PlaceInfo({'address': {'housenumber': '3'}})
47 name, address = PlaceSanitizer([{'step': 'strip-brace-terms'}]).process_names(place)
50 assert len(address) == 1