2 Tests for import name normalisation and variant generation.
4 from textwrap import dedent
8 from nominatim.tokenizer.icu_rule_loader import ICURuleLoader
9 from nominatim.tokenizer.icu_name_processor import ICUNameProcessor, ICUNameProcessorRules
11 from nominatim.errors import UsageError
14 def cfgfile(tmp_path, suffix='.yaml'):
15 def _create_config(suffixes, abbr):
19 - "[[:Nonspacing Mark:] [:Cf:]] >"
21 - "[[:Punctuation:][:Space:]]+ > ' '"
26 content += "compound_suffixes:\n"
27 content += '\n'.join((" - " + s for s in suffixes)) + '\n'
28 content += "abbreviations:\n"
29 content += '\n'.join((" - " + s for s in abbr)) + '\n'
30 fpath = tmp_path / ('test_config' + suffix)
31 fpath.write_text(dedent(content))
37 def test_simple_variants(cfgfile):
38 fpath = cfgfile(['strasse', 'straße', 'weg'],
39 ['strasse,straße => str',
42 rules = ICUNameProcessorRules(loader=ICURuleLoader(fpath))
43 proc = ICUNameProcessor(rules)
45 assert set(proc.get_normalized_variants("Bauwegstraße")) \
46 == {'bauweg straße', 'bauweg str'}
47 assert proc.get_normalized_variants("Bauwegstr") == ['bauweg str']
48 assert proc.get_normalized_variants("holzweg") == ['holz weg']
49 assert proc.get_normalized_variants("hallo") == ['hallo']
52 def test_multiple_replacements(cfgfile):
53 fpath = cfgfile([], ['saint => s,st', 'street => st'])
55 rules = ICUNameProcessorRules(loader=ICURuleLoader(fpath))
56 proc = ICUNameProcessor(rules)
58 assert set(proc.get_normalized_variants("Saint Johns Street")) == \
59 {'saint johns street', 's johns street', 'st johns street',
60 'saint johns st', 's johns st', 'st johns st'}