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