Nominatim/test/python/dummy_tokenizer.py

82 lines
1.8 KiB
Python
Raw Normal View History

2022-01-03 18:23:58 +03:00
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2022 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tokenizer for testing.
"""
from nominatim.data.place_info import PlaceInfo
from nominatim.config import Configuration
def create(dsn, data_dir):
""" Create a new instance of the tokenizer provided by this module.
"""
return DummyTokenizer(dsn, data_dir)
class DummyTokenizer:
def __init__(self, dsn, data_dir):
self.dsn = dsn
self.data_dir = data_dir
self.init_state = None
self.analyser_cache = {}
def init_new_db(self, *args, **kwargs):
2021-05-20 00:07:39 +03:00
assert self.init_state is None
self.init_state = "new"
def init_from_project(self, config):
assert isinstance(config, Configuration)
2021-05-20 00:07:39 +03:00
assert self.init_state is None
self.init_state = "loaded"
2021-05-20 00:07:39 +03:00
@staticmethod
def finalize_import(_):
pass
def name_analyzer(self):
return DummyNameAnalyzer(self.analyser_cache)
class DummyNameAnalyzer:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def __init__(self, cache):
self.analyser_cache = cache
cache['countries'] = []
def close(self):
pass
2021-05-20 00:07:39 +03:00
@staticmethod
def normalize_postcode(postcode):
return postcode
2021-05-20 00:07:39 +03:00
@staticmethod
def update_postcodes_from_db():
pass
def update_special_phrases(self, phrases, should_replace):
self.analyser_cache['special_phrases'] = phrases
def add_country_names(self, code, names):
self.analyser_cache['countries'].append((code, names))
2021-05-20 00:07:39 +03:00
@staticmethod
def process_place(place):
assert isinstance(place, PlaceInfo)
return {}