+ ], True)
+
+ assert word_table.get_special() \
+ == {('KÖNIG BEI', 'König bei', 'amenity', 'royal', 'near'),
+ ('KÖNIGE', 'Könige', 'amenity', 'royal', None),
+ ('STREET', 'street', 'highway', 'primary', 'in')}
+
+
+def test_update_special_phrase_delete_all(analyzer, word_table):
+ word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special('BAR', 'bar', 'highway', 'road', None)
+
+ assert word_table.count_special() == 2
+
+ with analyzer() as anl:
+ anl.update_special_phrases([], True)
+
+ assert word_table.count_special() == 0
+
+
+def test_update_special_phrases_no_replace(analyzer, word_table):
+ word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special('BAR', 'bar', 'highway', 'road', None)
+
+ assert word_table.count_special() == 2
+
+ with analyzer() as anl:
+ anl.update_special_phrases([], False)
+
+ assert word_table.count_special() == 2
+
+
+def test_update_special_phrase_modify(analyzer, word_table):
+ word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
+ word_table.add_special('BAR', 'bar', 'highway', 'road', None)
+
+ assert word_table.count_special() == 2
+
+ with analyzer() as anl:
+ anl.update_special_phrases([
+ ('prison', 'amenity', 'prison', 'in'),
+ ('bar', 'highway', 'road', '-'),
+ ('garden', 'leisure', 'garden', 'near')
+ ], True)
+
+ assert word_table.get_special() \
+ == {('PRISON', 'prison', 'amenity', 'prison', 'in'),
+ ('BAR', 'bar', 'highway', 'road', None),
+ ('GARDEN', 'garden', 'leisure', 'garden', 'near')}
+
+
+def test_add_country_names_new(analyzer, word_table):
+ with analyzer() as anl:
+ anl.add_country_names('es', {'name': 'Espagña', 'name:en': 'Spain'})
+
+ assert word_table.get_country() == {('es', 'ESPAGÑA'), ('es', 'SPAIN')}
+
+
+def test_add_country_names_extend(analyzer, word_table):
+ word_table.add_country('ch', 'SCHWEIZ')
+
+ with analyzer() as anl:
+ anl.add_country_names('ch', {'name': 'Schweiz', 'name:fr': 'Suisse'})
+
+ assert word_table.get_country() == {('ch', 'SCHWEIZ'), ('ch', 'SUISSE')}
+
+
+class TestPlaceNames:
+
+ @pytest.fixture(autouse=True)
+ def setup(self, analyzer, getorcreate_full_word):
+ with analyzer() as anl:
+ self.analyzer = anl
+ yield anl
+
+
+ def expect_name_terms(self, info, *expected_terms):
+ tokens = self.analyzer.get_word_token_info(expected_terms)
+ print (tokens)
+ for token in tokens:
+ assert token[2] is not None, "No token for {0}".format(token)
+
+ assert eval(info['names']) == set((t[2] for t in tokens))
+
+
+ def test_simple_names(self):
+ info = self.analyzer.process_place({'name': {'name': 'Soft bAr', 'ref': '34'}})
+
+ self.expect_name_terms(info, '#Soft bAr', '#34', 'Soft', 'bAr', '34')
+
+
+ @pytest.mark.parametrize('sep', [',' , ';'])
+ def test_names_with_separator(self, sep):
+ info = self.analyzer.process_place({'name': {'name': sep.join(('New York', 'Big Apple'))}})
+
+ self.expect_name_terms(info, '#New York', '#Big Apple',
+ 'new', 'york', 'big', 'apple')
+
+
+ def test_full_names_with_bracket(self):
+ info = self.analyzer.process_place({'name': {'name': 'Houseboat (left)'}})
+
+ self.expect_name_terms(info, '#Houseboat (left)', '#Houseboat',
+ 'houseboat', 'left')
+
+
+ def test_country_name(self, word_table):
+ info = self.analyzer.process_place({'name': {'name': 'Norge'},
+ 'country_feature': 'no'})
+
+ self.expect_name_terms(info, '#norge', 'norge')
+ assert word_table.get_country() == {('no', 'NORGE')}
+
+
+class TestPlaceAddress:
+
+ @pytest.fixture(autouse=True)
+ def setup(self, analyzer, getorcreate_full_word):
+ with analyzer(trans=(":: upper()", "'🜵' > ' '")) as anl:
+ self.analyzer = anl
+ yield anl
+
+
+ def process_address(self, **kwargs):
+ return self.analyzer.process_place({'address': kwargs})
+
+
+ def name_token_set(self, *expected_terms):
+ tokens = self.analyzer.get_word_token_info(expected_terms)
+ for token in tokens:
+ assert token[2] is not None, "No token for {0}".format(token)
+
+ return set((t[2] for t in tokens))
+
+
+ @pytest.mark.parametrize('pcode', ['12345', 'AB 123', '34-345'])
+ def test_process_place_postcode(self, word_table, pcode):
+ self.process_address(postcode=pcode)
+
+ assert word_table.get_postcodes() == {pcode, }
+
+
+ @pytest.mark.parametrize('pcode', ['12:23', 'ab;cd;f', '123;836'])
+ def test_process_place_bad_postcode(self, word_table, pcode):
+ self.process_address(postcode=pcode)
+
+ assert not word_table.get_postcodes()
+
+
+ @pytest.mark.parametrize('hnr', ['123a', '1', '101'])
+ def test_process_place_housenumbers_simple(self, hnr, getorcreate_hnr_id):
+ info = self.process_address(housenumber=hnr)
+
+ assert info['hnr'] == hnr.upper()
+ assert info['hnr_tokens'] == "{-1}"
+
+
+ def test_process_place_housenumbers_lists(self, getorcreate_hnr_id):
+ info = self.process_address(conscriptionnumber='1; 2;3')