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.
|
2021-04-21 10:57:17 +03:00
|
|
|
"""
|
|
|
|
Tokenizer for testing.
|
|
|
|
"""
|
2022-07-06 11:54:47 +03:00
|
|
|
from nominatim.data.place_info import PlaceInfo
|
2021-09-29 18:37:04 +03:00
|
|
|
from nominatim.config import Configuration
|
2021-04-21 10:57:17 +03:00
|
|
|
|
|
|
|
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
|
2021-04-27 12:37:18 +03:00
|
|
|
self.analyser_cache = {}
|
2021-04-21 10:57:17 +03:00
|
|
|
|
|
|
|
|
2021-04-28 11:59:07 +03:00
|
|
|
def init_new_db(self, *args, **kwargs):
|
2021-05-20 00:07:39 +03:00
|
|
|
assert self.init_state is None
|
2021-04-21 10:57:17 +03:00
|
|
|
self.init_state = "new"
|
|
|
|
|
|
|
|
|
2021-09-29 18:37:04 +03:00
|
|
|
def init_from_project(self, config):
|
|
|
|
assert isinstance(config, Configuration)
|
2021-05-20 00:07:39 +03:00
|
|
|
assert self.init_state is None
|
2021-04-21 10:57:17 +03:00
|
|
|
self.init_state = "loaded"
|
2021-04-24 23:35:46 +03:00
|
|
|
|
|
|
|
|
2021-05-20 00:07:39 +03:00
|
|
|
@staticmethod
|
|
|
|
def finalize_import(_):
|
2021-04-30 18:28:34 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-04-24 23:35:46 +03:00
|
|
|
def name_analyzer(self):
|
2021-04-27 12:37:18 +03:00
|
|
|
return DummyNameAnalyzer(self.analyser_cache)
|
2021-04-24 23:35:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
class DummyNameAnalyzer:
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
|
2021-04-27 12:37:18 +03:00
|
|
|
def __init__(self, cache):
|
|
|
|
self.analyser_cache = cache
|
|
|
|
cache['countries'] = []
|
|
|
|
|
|
|
|
|
2021-04-24 23:35:46 +03:00
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
2021-05-20 00:07:39 +03:00
|
|
|
@staticmethod
|
|
|
|
def normalize_postcode(postcode):
|
2021-05-13 00:30:45 +03:00
|
|
|
return postcode
|
|
|
|
|
2021-05-20 00:07:39 +03:00
|
|
|
@staticmethod
|
|
|
|
def update_postcodes_from_db():
|
2021-04-25 19:26:36 +03:00
|
|
|
pass
|
|
|
|
|
2021-05-17 13:40:50 +03:00
|
|
|
def update_special_phrases(self, phrases, should_replace):
|
2021-04-27 22:50:35 +03:00
|
|
|
self.analyser_cache['special_phrases'] = phrases
|
2021-04-24 23:35:46 +03:00
|
|
|
|
2021-04-27 12:37:18 +03:00
|
|
|
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):
|
2021-09-29 11:37:54 +03:00
|
|
|
assert isinstance(place, PlaceInfo)
|
2021-04-24 23:35:46 +03:00
|
|
|
return {}
|