X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b240b182cb0cc6cff6c07ef26375012c3126e2e5..a0ed80d821bd3f7938a2e3d4e38357f0c03b919e:/nominatim/tokenizer/legacy_tokenizer.py diff --git a/nominatim/tokenizer/legacy_tokenizer.py b/nominatim/tokenizer/legacy_tokenizer.py index 0edcdcca..3b8f7569 100644 --- a/nominatim/tokenizer/legacy_tokenizer.py +++ b/nominatim/tokenizer/legacy_tokenizer.py @@ -1,3 +1,9 @@ +# 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 implementing normalisation as used before Nominatim 4. """ @@ -101,7 +107,7 @@ class LegacyTokenizer(AbstractTokenizer): self.normalization = config.TERM_NORMALIZATION - self._install_php(config) + self._install_php(config, overwrite=True) with connect(self.dsn) as conn: _check_module(module_dir, conn) @@ -113,12 +119,18 @@ class LegacyTokenizer(AbstractTokenizer): self._init_db_tables(config) - def init_from_project(self, _): + def init_from_project(self, config): """ Initialise the tokenizer from the project directory. """ with connect(self.dsn) as conn: self.normalization = properties.get_property(conn, DBCFG_NORMALIZATION) + if not (config.project_dir / 'module' / 'nominatim.so').exists(): + _install_module(config.DATABASE_MODULE_PATH, + config.lib_dir.module, + config.project_dir / 'module') + + self._install_php(config, overwrite=False) def finalize_import(self, config): """ Do any required postprocessing to make the tokenizer data ready @@ -205,6 +217,13 @@ class LegacyTokenizer(AbstractTokenizer): cur.drop_table("word_frequencies") conn.commit() + + def update_word_tokens(self): + """ No house-keeping implemented for the legacy tokenizer. + """ + LOG.info("No tokenizer clean-up available.") + + def name_analyzer(self): """ Create a new analyzer for tokenizing names and queries using this tokinzer. Analyzers are context managers and should @@ -225,16 +244,18 @@ class LegacyTokenizer(AbstractTokenizer): return LegacyNameAnalyzer(self.dsn, normalizer) - def _install_php(self, config): + def _install_php(self, config, overwrite=True): """ Install the php script for the tokenizer. """ php_file = self.data_dir / "tokenizer.php" - php_file.write_text(dedent("""\ -