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