]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/test_icu.py
release 5.0.0.post6
[nominatim.git] / test / python / tokenizer / test_icu.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for ICU tokenizer.
9 """
10 import yaml
11 import itertools
12
13 import pytest
14
15 from nominatim_db.tokenizer import icu_tokenizer
16 import nominatim_db.tokenizer.icu_rule_loader
17 from nominatim_db.db import properties
18 from nominatim_db.db.sql_preprocessor import SQLPreprocessor
19 from nominatim_db.data.place_info import PlaceInfo
20
21 from mock_icu_word_table import MockIcuWordTable
22
23 @pytest.fixture
24 def word_table(temp_db_conn):
25     return MockIcuWordTable(temp_db_conn)
26
27
28 @pytest.fixture
29 def test_config(project_env, tmp_path):
30     sqldir = tmp_path / 'sql'
31     sqldir.mkdir()
32     (sqldir / 'tokenizer').mkdir()
33     (sqldir / 'tokenizer' / 'icu_tokenizer.sql').write_text("SELECT 'a'")
34
35     project_env.lib_dir.sql = sqldir
36
37     return project_env
38
39
40 @pytest.fixture
41 def tokenizer_factory(dsn, tmp_path, property_table,
42                       sql_preprocessor, place_table, word_table):
43     (tmp_path / 'tokenizer').mkdir()
44
45     def _maker():
46         return icu_tokenizer.create(dsn, tmp_path / 'tokenizer')
47
48     return _maker
49
50
51 @pytest.fixture
52 def db_prop(temp_db_conn):
53     def _get_db_property(name):
54         return properties.get_property(temp_db_conn, name)
55
56     return _get_db_property
57
58
59 @pytest.fixture
60 def analyzer(tokenizer_factory, test_config, monkeypatch,
61              temp_db_with_extensions, tmp_path):
62     sql = tmp_path / 'sql' / 'tokenizer' / 'icu_tokenizer.sql'
63     sql.write_text("SELECT 'a';")
64
65     monkeypatch.setenv('NOMINATIM_TERM_NORMALIZATION', ':: lower();')
66     tok = tokenizer_factory()
67     tok.init_new_db(test_config)
68     monkeypatch.undo()
69
70     def _mk_analyser(norm=("[[:Punctuation:][:Space:]]+ > ' '",), trans=(':: upper()',),
71                      variants=('~gasse -> gasse', 'street => st', ),
72                      sanitizers=[], with_housenumber=False,
73                      with_postcode=False):
74         cfgstr = {'normalization': list(norm),
75                   'sanitizers': sanitizers,
76                   'transliteration': list(trans),
77                   'token-analysis': [{'analyzer': 'generic',
78                                       'variants': [{'words': list(variants)}]}]}
79         if with_housenumber:
80             cfgstr['token-analysis'].append({'id': '@housenumber',
81                                              'analyzer': 'housenumbers'})
82         if with_postcode:
83             cfgstr['token-analysis'].append({'id': '@postcode',
84                                              'analyzer': 'postcodes'})
85         (test_config.project_dir / 'icu_tokenizer.yaml').write_text(yaml.dump(cfgstr))
86         tok.loader = nominatim_db.tokenizer.icu_rule_loader.ICURuleLoader(test_config)
87
88         return tok.name_analyzer()
89
90     return _mk_analyser
91
92 @pytest.fixture
93 def sql_functions(temp_db_conn, def_config, src_dir):
94     orig_sql = def_config.lib_dir.sql
95     def_config.lib_dir.sql = src_dir / 'lib-sql'
96     sqlproc = SQLPreprocessor(temp_db_conn, def_config)
97     sqlproc.run_sql_file(temp_db_conn, 'functions/utils.sql')
98     sqlproc.run_sql_file(temp_db_conn, 'tokenizer/icu_tokenizer.sql')
99     def_config.lib_dir.sql = orig_sql
100
101
102 @pytest.fixture
103 def getorcreate_full_word(temp_db_cursor):
104     temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION getorcreate_full_word(
105                                                  norm_term TEXT, lookup_terms TEXT[],
106                                                  OUT full_token INT,
107                                                  OUT partial_tokens INT[])
108   AS $$
109 DECLARE
110   partial_terms TEXT[] = '{}'::TEXT[];
111   term TEXT;
112   term_id INTEGER;
113   term_count INTEGER;
114 BEGIN
115   SELECT min(word_id) INTO full_token
116     FROM word WHERE info->>'word' = norm_term and type = 'W';
117
118   IF full_token IS NULL THEN
119     full_token := nextval('seq_word');
120     INSERT INTO word (word_id, word_token, type, info)
121       SELECT full_token, lookup_term, 'W',
122              json_build_object('word', norm_term, 'count', 0)
123         FROM unnest(lookup_terms) as lookup_term;
124   END IF;
125
126   FOR term IN SELECT unnest(string_to_array(unnest(lookup_terms), ' ')) LOOP
127     term := trim(term);
128     IF NOT (ARRAY[term] <@ partial_terms) THEN
129       partial_terms := partial_terms || term;
130     END IF;
131   END LOOP;
132
133   partial_tokens := '{}'::INT[];
134   FOR term IN SELECT unnest(partial_terms) LOOP
135     SELECT min(word_id), max(info->>'count') INTO term_id, term_count
136       FROM word WHERE word_token = term and type = 'w';
137
138     IF term_id IS NULL THEN
139       term_id := nextval('seq_word');
140       term_count := 0;
141       INSERT INTO word (word_id, word_token, type, info)
142         VALUES (term_id, term, 'w', json_build_object('count', term_count));
143     END IF;
144
145     IF NOT (ARRAY[term_id] <@ partial_tokens) THEN
146       partial_tokens := partial_tokens || term_id;
147     END IF;
148   END LOOP;
149 END;
150 $$
151 LANGUAGE plpgsql;
152                               """)
153
154
155
156 def test_init_new(tokenizer_factory, test_config, db_prop):
157     tok = tokenizer_factory()
158     tok.init_new_db(test_config)
159
160     assert db_prop(nominatim_db.tokenizer.icu_rule_loader.DBCFG_IMPORT_NORM_RULES) \
161             .startswith(':: lower ();')
162
163
164 def test_init_word_table(tokenizer_factory, test_config, place_row, temp_db_cursor):
165     place_row(names={'name' : 'Test Area', 'ref' : '52'})
166     place_row(names={'name' : 'No Area'})
167     place_row(names={'name' : 'Holzstrasse'})
168
169     tok = tokenizer_factory()
170     tok.init_new_db(test_config)
171
172     assert temp_db_cursor.table_exists('word')
173
174
175 def test_init_from_project(test_config, tokenizer_factory):
176     tok = tokenizer_factory()
177     tok.init_new_db(test_config)
178
179     tok = tokenizer_factory()
180     tok.init_from_project(test_config)
181
182     assert tok.loader is not None
183
184
185 def test_update_sql_functions(db_prop, temp_db_cursor,
186                               tokenizer_factory, test_config, table_factory,
187                               monkeypatch):
188     tok = tokenizer_factory()
189     tok.init_new_db(test_config)
190
191     table_factory('test', 'txt TEXT')
192
193     func_file = test_config.lib_dir.sql / 'tokenizer' / 'icu_tokenizer.sql'
194     func_file.write_text("""INSERT INTO test VALUES (1133)""")
195
196     tok.update_sql_functions(test_config)
197
198     test_content = temp_db_cursor.row_set('SELECT * FROM test')
199     assert test_content == set((('1133', ), ))
200
201
202 def test_finalize_import(tokenizer_factory, temp_db_cursor,
203                          test_config, sql_preprocessor_cfg):
204     tok = tokenizer_factory()
205     tok.init_new_db(test_config)
206
207     assert not temp_db_cursor.index_exists('word', 'idx_word_word_id')
208
209     tok.finalize_import(test_config)
210
211     assert temp_db_cursor.index_exists('word', 'idx_word_word_id')
212
213
214 def test_check_database(test_config, tokenizer_factory,
215                         temp_db_cursor, sql_preprocessor_cfg):
216     tok = tokenizer_factory()
217     tok.init_new_db(test_config)
218
219     assert tok.check_database(test_config) is None
220
221
222 def test_update_statistics_reverse_only(word_table, tokenizer_factory, test_config):
223     tok = tokenizer_factory()
224     tok.update_statistics(test_config)
225
226
227 def test_update_statistics(word_table, table_factory, temp_db_cursor,
228                            tokenizer_factory, test_config):
229     word_table.add_full_word(1000, 'hello')
230     word_table.add_full_word(1001, 'bye')
231     table_factory('search_name',
232                   'place_id BIGINT, name_vector INT[], nameaddress_vector INT[]',
233                   [(12, [1000], [1001])])
234     tok = tokenizer_factory()
235
236     tok.update_statistics(test_config)
237
238     assert temp_db_cursor.scalar("""SELECT count(*) FROM word
239                                     WHERE type = 'W' and word_id = 1000 and
240                                           (info->>'count')::int > 0""") == 1
241     assert temp_db_cursor.scalar("""SELECT count(*) FROM word
242                                     WHERE type = 'W' and word_id = 1001 and
243                                           (info->>'addr_count')::int > 0""") == 1
244
245
246 def test_normalize_postcode(analyzer):
247     with analyzer() as anl:
248         anl.normalize_postcode('123') == '123'
249         anl.normalize_postcode('ab-34 ') == 'AB-34'
250         anl.normalize_postcode('38 Б') == '38 Б'
251
252
253 class TestPostcodes:
254
255     @pytest.fixture(autouse=True)
256     def setup(self, analyzer, sql_functions):
257         sanitizers = [{'step': 'clean-postcodes'}]
258         with analyzer(sanitizers=sanitizers, with_postcode=True) as anl:
259             self.analyzer = anl
260             yield anl
261
262
263     def process_postcode(self, cc, postcode):
264         return self.analyzer.process_place(PlaceInfo({'country_code': cc,
265                                                       'address': {'postcode': postcode}}))
266
267
268     def test_update_postcodes_deleted(self, word_table):
269         word_table.add_postcode(' 1234', '1234')
270         word_table.add_postcode(' 5678', '5678')
271
272         self.analyzer.update_postcodes_from_db()
273
274         assert word_table.count() == 0
275
276
277     def test_process_place_postcode_simple(self, word_table):
278         info = self.process_postcode('de', '12345')
279
280         assert info['postcode'] == '12345'
281
282
283     def test_process_place_postcode_with_space(self, word_table):
284         info = self.process_postcode('in', '123 567')
285
286         assert info['postcode'] == '123567'
287
288
289
290 def test_update_special_phrase_empty_table(analyzer, word_table):
291     with analyzer() as anl:
292         anl.update_special_phrases([
293             ("König  bei", "amenity", "royal", "near"),
294             ("Könige ", "amenity", "royal", "-"),
295             ("street", "highway", "primary", "in")
296         ], True)
297
298     assert word_table.get_special() \
299                == {('KÖNIG BEI', 'König bei', 'amenity', 'royal', 'near'),
300                    ('KÖNIGE', 'Könige', 'amenity', 'royal', None),
301                    ('STREET', 'street', 'highway', 'primary', 'in')}
302
303
304 def test_update_special_phrase_delete_all(analyzer, word_table):
305     word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
306     word_table.add_special('BAR', 'bar', 'highway', 'road', None)
307
308     assert word_table.count_special() == 2
309
310     with analyzer() as anl:
311         anl.update_special_phrases([], True)
312
313     assert word_table.count_special() == 0
314
315
316 def test_update_special_phrases_no_replace(analyzer, word_table):
317     word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
318     word_table.add_special('BAR', 'bar', 'highway', 'road', None)
319
320     assert word_table.count_special() == 2
321
322     with analyzer() as anl:
323         anl.update_special_phrases([], False)
324
325     assert word_table.count_special() == 2
326
327
328 def test_update_special_phrase_modify(analyzer, word_table):
329     word_table.add_special('FOO', 'foo', 'amenity', 'prison', 'in')
330     word_table.add_special('BAR', 'bar', 'highway', 'road', None)
331
332     assert word_table.count_special() == 2
333
334     with analyzer() as anl:
335         anl.update_special_phrases([
336             ('prison', 'amenity', 'prison', 'in'),
337             ('bar', 'highway', 'road', '-'),
338             ('garden', 'leisure', 'garden', 'near')
339         ], True)
340
341     assert word_table.get_special() \
342                == {('PRISON', 'prison', 'amenity', 'prison', 'in'),
343                    ('BAR', 'bar', 'highway', 'road', None),
344                    ('GARDEN', 'garden', 'leisure', 'garden', 'near')}
345
346
347 def test_add_country_names_new(analyzer, word_table):
348     with analyzer() as anl:
349         anl.add_country_names('es', {'name': 'Espagña', 'name:en': 'Spain'})
350
351     assert word_table.get_country() == {('es', 'ESPAGÑA'), ('es', 'SPAIN')}
352
353
354 def test_add_country_names_extend(analyzer, word_table):
355     word_table.add_country('ch', 'SCHWEIZ')
356
357     with analyzer() as anl:
358         anl.add_country_names('ch', {'name': 'Schweiz', 'name:fr': 'Suisse'})
359
360     assert word_table.get_country() == {('ch', 'SCHWEIZ'), ('ch', 'SUISSE')}
361
362
363 class TestPlaceNames:
364
365     @pytest.fixture(autouse=True)
366     def setup(self, analyzer, sql_functions):
367         sanitizers = [{'step': 'split-name-list'},
368                       {'step': 'strip-brace-terms'}]
369         with analyzer(sanitizers=sanitizers) as anl:
370             self.analyzer = anl
371             yield anl
372
373
374     def expect_name_terms(self, info, *expected_terms):
375         tokens = self.analyzer.get_word_token_info(expected_terms)
376         for token in tokens:
377             assert token[2] is not None, "No token for {0}".format(token)
378
379         assert eval(info['names']) == set((t[2] for t in tokens))
380
381
382     def process_named_place(self, names):
383         return self.analyzer.process_place(PlaceInfo({'name': names}))
384
385
386     def test_simple_names(self):
387         info = self.process_named_place({'name': 'Soft bAr', 'ref': '34'})
388
389         self.expect_name_terms(info, '#Soft bAr', '#34', 'Soft', 'bAr', '34')
390
391
392     @pytest.mark.parametrize('sep', [',' , ';'])
393     def test_names_with_separator(self, sep):
394         info = self.process_named_place({'name': sep.join(('New York', 'Big Apple'))})
395
396         self.expect_name_terms(info, '#New York', '#Big Apple',
397                                      'new', 'york', 'big', 'apple')
398
399
400     def test_full_names_with_bracket(self):
401         info = self.process_named_place({'name': 'Houseboat (left)'})
402
403         self.expect_name_terms(info, '#Houseboat (left)', '#Houseboat',
404                                      'houseboat', 'left')
405
406
407     def test_country_name(self, word_table):
408         place = PlaceInfo({'name' : {'name': 'Norge'},
409                            'country_code': 'no',
410                            'rank_address': 4,
411                            'class': 'boundary',
412                            'type': 'administrative'})
413
414         info = self.analyzer.process_place(place)
415
416         self.expect_name_terms(info, '#norge', 'norge')
417         assert word_table.get_country() == {('no', 'NORGE')}
418
419
420 class TestPlaceAddress:
421
422     @pytest.fixture(autouse=True)
423     def setup(self, analyzer, sql_functions):
424         hnr = {'step': 'clean-housenumbers',
425                'filter-kind': ['housenumber', 'conscriptionnumber', 'streetnumber']}
426         with analyzer(trans=(":: upper()", "'🜵' > ' '"), sanitizers=[hnr]) as anl:
427             self.analyzer = anl
428             yield anl
429
430
431     @pytest.fixture
432     def getorcreate_hnr_id(self, temp_db_cursor):
433         temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION getorcreate_hnr_id(lookup_term TEXT)
434                                   RETURNS INTEGER AS $$
435                                     SELECT -nextval('seq_word')::INTEGER; $$ LANGUAGE SQL""")
436
437
438     def process_address(self, **kwargs):
439         return self.analyzer.process_place(PlaceInfo({'address': kwargs}))
440
441
442     def name_token_set(self, *expected_terms):
443         tokens = self.analyzer.get_word_token_info(expected_terms)
444         for token in tokens:
445             assert token[2] is not None, "No token for {0}".format(token)
446
447         return set((t[2] for t in tokens))
448
449
450     @pytest.mark.parametrize('pcode', ['12345', 'AB 123', '34-345'])
451     def test_process_place_postcode(self, word_table, pcode):
452         info = self.process_address(postcode=pcode)
453
454         assert info['postcode'] == pcode
455
456
457     @pytest.mark.parametrize('hnr', ['123a', '1', '101'])
458     def test_process_place_housenumbers_simple(self, hnr, getorcreate_hnr_id):
459         info = self.process_address(housenumber=hnr)
460
461         assert info['hnr'] == hnr.upper()
462         assert info['hnr_tokens'] == "{-1}"
463
464
465     def test_process_place_housenumbers_duplicates(self, getorcreate_hnr_id):
466         info = self.process_address(housenumber='134',
467                                     conscriptionnumber='134',
468                                     streetnumber='99a')
469
470         assert set(info['hnr'].split(';')) == set(('134', '99A'))
471         assert info['hnr_tokens'] == "{-1,-2}"
472
473
474     def test_process_place_housenumbers_cached(self, getorcreate_hnr_id):
475         info = self.process_address(housenumber="45")
476         assert info['hnr_tokens'] == "{-1}"
477
478         info = self.process_address(housenumber="46")
479         assert info['hnr_tokens'] == "{-2}"
480
481         info = self.process_address(housenumber="41;45")
482         assert eval(info['hnr_tokens']) == {-1, -3}
483
484         info = self.process_address(housenumber="41")
485         assert eval(info['hnr_tokens']) == {-3}
486
487
488     def test_process_place_street(self):
489         self.analyzer.process_place(PlaceInfo({'name': {'name' : 'Grand Road'}}))
490         info = self.process_address(street='Grand Road')
491
492         assert eval(info['street']) == self.name_token_set('#Grand Road')
493
494
495     def test_process_place_nonexisting_street(self):
496         info = self.process_address(street='Grand Road')
497
498         assert info['street'] == '{}'
499
500
501     def test_process_place_multiple_street_tags(self):
502         self.analyzer.process_place(PlaceInfo({'name': {'name' : 'Grand Road',
503                                                         'ref': '05989'}}))
504         info = self.process_address(**{'street': 'Grand Road',
505                                       'street:sym_ul': '05989'})
506
507         assert eval(info['street']) == self.name_token_set('#Grand Road', '#05989')
508
509
510     def test_process_place_street_empty(self):
511         info = self.process_address(street='🜵')
512
513         assert info['street'] == '{}'
514
515
516     def test_process_place_street_from_cache(self):
517         self.analyzer.process_place(PlaceInfo({'name': {'name' : 'Grand Road'}}))
518         self.process_address(street='Grand Road')
519
520         # request address again
521         info = self.process_address(street='Grand Road')
522
523         assert eval(info['street']) == self.name_token_set('#Grand Road')
524
525
526     def test_process_place_place(self):
527         info = self.process_address(place='Honu Lulu')
528
529         assert eval(info['place']) == self.name_token_set('HONU', 'LULU', '#HONU LULU')
530
531
532     def test_process_place_place_extra(self):
533         info = self.process_address(**{'place:en': 'Honu Lulu'})
534
535         assert 'place' not in info
536
537
538     def test_process_place_place_empty(self):
539         info = self.process_address(place='🜵')
540
541         assert 'place' not in info
542
543
544     def test_process_place_address_terms(self):
545         info = self.process_address(country='de', city='Zwickau', state='Sachsen',
546                                     suburb='Zwickau', street='Hauptstr',
547                                     full='right behind the church')
548
549         city = self.name_token_set('ZWICKAU', '#ZWICKAU')
550         state = self.name_token_set('SACHSEN', '#SACHSEN')
551
552         result = {k: eval(v) for k,v in info['addr'].items()}
553
554         assert result == {'city': city, 'suburb': city, 'state': state}
555
556
557     def test_process_place_multiple_address_terms(self):
558         info = self.process_address(**{'city': 'Bruxelles', 'city:de': 'Brüssel'})
559
560         result = {k: eval(v) for k,v in info['addr'].items()}
561
562         assert result == {'city': self.name_token_set('Bruxelles', '#Bruxelles')}
563
564
565     def test_process_place_address_terms_empty(self):
566         info = self.process_address(country='de', city=' ', street='Hauptstr',
567                                     full='right behind the church')
568
569         assert 'addr' not in info
570
571
572 class TestPlaceHousenumberWithAnalyser:
573
574     @pytest.fixture(autouse=True)
575     def setup(self, analyzer, sql_functions):
576         hnr = {'step': 'clean-housenumbers',
577                'filter-kind': ['housenumber', 'conscriptionnumber', 'streetnumber']}
578         with analyzer(trans=(":: upper()", "'🜵' > ' '"), sanitizers=[hnr], with_housenumber=True) as anl:
579             self.analyzer = anl
580             yield anl
581
582
583     @pytest.fixture
584     def getorcreate_hnr_id(self, temp_db_cursor):
585         temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION create_analyzed_hnr_id(norm_term TEXT, lookup_terms TEXT[])
586                                   RETURNS INTEGER AS $$
587                                     SELECT -nextval('seq_word')::INTEGER; $$ LANGUAGE SQL""")
588
589
590     def process_address(self, **kwargs):
591         return self.analyzer.process_place(PlaceInfo({'address': kwargs}))
592
593
594     def name_token_set(self, *expected_terms):
595         tokens = self.analyzer.get_word_token_info(expected_terms)
596         for token in tokens:
597             assert token[2] is not None, "No token for {0}".format(token)
598
599         return set((t[2] for t in tokens))
600
601
602     @pytest.mark.parametrize('hnr', ['123 a', '1', '101'])
603     def test_process_place_housenumbers_simple(self, hnr, getorcreate_hnr_id):
604         info = self.process_address(housenumber=hnr)
605
606         assert info['hnr'] == hnr.upper()
607         assert info['hnr_tokens'] == "{-1}"
608
609
610     def test_process_place_housenumbers_duplicates(self, getorcreate_hnr_id):
611         info = self.process_address(housenumber='134',
612                                     conscriptionnumber='134',
613                                     streetnumber='99a')
614
615         assert set(info['hnr'].split(';')) == set(('134', '99 A'))
616         assert info['hnr_tokens'] == "{-1,-2}"
617
618
619     def test_process_place_housenumbers_cached(self, getorcreate_hnr_id):
620         info = self.process_address(housenumber="45")
621         assert info['hnr_tokens'] == "{-1}"
622
623         info = self.process_address(housenumber="46")
624         assert info['hnr_tokens'] == "{-2}"
625
626         info = self.process_address(housenumber="41;45")
627         assert eval(info['hnr_tokens']) == {-1, -3}
628
629         info = self.process_address(housenumber="41")
630         assert eval(info['hnr_tokens']) == {-3}
631
632
633 class TestUpdateWordTokens:
634
635     @pytest.fixture(autouse=True)
636     def setup(self, tokenizer_factory, table_factory, placex_table, word_table):
637         table_factory('search_name', 'place_id BIGINT, name_vector INT[]')
638         self.tok = tokenizer_factory()
639
640
641     @pytest.fixture
642     def search_entry(self, temp_db_cursor):
643         place_id = itertools.count(1000)
644
645         def _insert(*args):
646             temp_db_cursor.execute("INSERT INTO search_name VALUES (%s, %s)",
647                                    (next(place_id), list(args)))
648
649         return _insert
650
651
652     @pytest.fixture(params=['simple', 'analyzed'])
653     def add_housenumber(self, request, word_table):
654         if request.param == 'simple':
655             def _make(hid, hnr):
656                 word_table.add_housenumber(hid, hnr)
657         elif request.param == 'analyzed':
658             def _make(hid, hnr):
659                 word_table.add_housenumber(hid, [hnr])
660
661         return _make
662
663
664     @pytest.mark.parametrize('hnr', ('1a', '1234567', '34 5'))
665     def test_remove_unused_housenumbers(self, add_housenumber, word_table, hnr):
666         word_table.add_housenumber(1000, hnr)
667
668         assert word_table.count_housenumbers() == 1
669         self.tok.update_word_tokens()
670         assert word_table.count_housenumbers() == 0
671
672
673     def test_keep_unused_numeral_housenumbers(self, add_housenumber, word_table):
674         add_housenumber(1000, '5432')
675
676         assert word_table.count_housenumbers() == 1
677         self.tok.update_word_tokens()
678         assert word_table.count_housenumbers() == 1
679
680
681     def test_keep_housenumbers_from_search_name_table(self, add_housenumber, word_table, search_entry):
682         add_housenumber(9999, '5432a')
683         add_housenumber(9991, '9 a')
684         search_entry(123, 9999, 34)
685
686         assert word_table.count_housenumbers() == 2
687         self.tok.update_word_tokens()
688         assert word_table.count_housenumbers() == 1
689
690
691     def test_keep_housenumbers_from_placex_table(self, add_housenumber, word_table, placex_table):
692         add_housenumber(9999, '5432a')
693         add_housenumber(9990, '34z')
694         placex_table.add(housenumber='34z')
695         placex_table.add(housenumber='25432a')
696
697         assert word_table.count_housenumbers() == 2
698         self.tok.update_word_tokens()
699         assert word_table.count_housenumbers() == 1
700
701
702     def test_keep_housenumbers_from_placex_table_hnr_list(self, add_housenumber, word_table, placex_table):
703         add_housenumber(9991, '9 b')
704         add_housenumber(9990, '34z')
705         placex_table.add(housenumber='9 a;9 b;9 c')
706
707         assert word_table.count_housenumbers() == 2
708         self.tok.update_word_tokens()
709         assert word_table.count_housenumbers() == 1