]> git.openstreetmap.org Git - nominatim.git/blob - test/python/dummy_tokenizer.py
db0f32cda6a1f95b1e590a8b7b1ef4be83975659
[nominatim.git] / test / python / dummy_tokenizer.py
1 """
2 Tokenizer for testing.
3 """
4 from nominatim.indexer.place_info import PlaceInfo
5
6 def create(dsn, data_dir):
7     """ Create a new instance of the tokenizer provided by this module.
8     """
9     return DummyTokenizer(dsn, data_dir)
10
11 class DummyTokenizer:
12
13     def __init__(self, dsn, data_dir):
14         self.dsn = dsn
15         self.data_dir = data_dir
16         self.init_state = None
17         self.analyser_cache = {}
18
19
20     def init_new_db(self, *args, **kwargs):
21         assert self.init_state is None
22         self.init_state = "new"
23
24
25     def init_from_project(self):
26         assert self.init_state is None
27         self.init_state = "loaded"
28
29
30     @staticmethod
31     def finalize_import(_):
32         pass
33
34
35     def name_analyzer(self):
36         return DummyNameAnalyzer(self.analyser_cache)
37
38
39 class DummyNameAnalyzer:
40
41     def __enter__(self):
42         return self
43
44     def __exit__(self, exc_type, exc_value, traceback):
45         self.close()
46
47
48     def __init__(self, cache):
49         self.analyser_cache = cache
50         cache['countries'] = []
51
52
53     def close(self):
54         pass
55
56     @staticmethod
57     def normalize_postcode(postcode):
58         return postcode
59
60     @staticmethod
61     def update_postcodes_from_db():
62         pass
63
64     def update_special_phrases(self, phrases, should_replace):
65         self.analyser_cache['special_phrases'] = phrases
66
67     def add_country_names(self, code, names):
68         self.analyser_cache['countries'].append((code, names))
69
70     @staticmethod
71     def process_place(place):
72         assert isinstance(place, PlaceInfo)
73         return {}