| -------------- | --------------------------------------------------- |
| **Description:** | Configuration file for rank assignments |
| **Format:** | path |
-| **Default:** | _empty_ (use default settings) |
+| **Default:** | address-levels.json |
-The _address level config_ configures rank assignments for places. See
+The _address level configuration_ defines the rank assignments for places. See
[Place Ranking](Ranking.md) for a detailed explanation what rank assignments
-are and what the configuration file must look like. The default configuration
-can be found in the configuration directory as `address-levels.json`.
+are and what the configuration file must look like.
+
+When a relative path is given, then the file is searched first relative to the
+project directory and then in the global settings directory.
+
#### NOMINATIM_IMPORT_STYLE
self._get_tokenizer(args.config).update_statistics()
if args.address_levels:
- cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
- LOG.warning('Updating address levels from %s', cfg)
+ LOG.warning('Updating address levels')
with connect(args.config.get_libpq_dsn()) as conn:
- refresh.load_address_levels_from_file(conn, cfg)
+ refresh.load_address_levels_from_config(conn, args.config)
if args.functions:
LOG.warning('Create functions')
refresh.create_functions(conn, config, False, False)
LOG.warning('Create tables')
database_import.create_tables(conn, config, reverse_only=reverse_only)
- refresh.load_address_levels_from_file(conn, Path(config.ADDRESS_LEVEL_CONFIG))
+ refresh.load_address_levels_from_config(conn, config)
LOG.warning('Create functions (2nd pass)')
refresh.create_functions(conn, config, False, False)
LOG.warning('Create table triggers')
if project_dir is not None and (project_dir / '.env').is_file():
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
- # Add defaults for variables that are left empty to set the default.
- # They may still be overwritten by environment variables.
- if not self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG']:
- self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG'] = \
- str(config_dir / 'address-levels.json')
-
class _LibDirs:
pass
"""
Functions for bringing auxiliary data in the database up-to-date.
"""
-import json
import logging
from textwrap import dedent
conn.commit()
-def load_address_levels_from_file(conn, config_file):
- """ Replace the `address_levels` table with the contents of the config
- file.
+
+def load_address_levels_from_config(conn, config):
+ """ Replace the `address_levels` table with the content as
+ defined in the given configuration. Uses the parameter
+ NOMINATIM_ADDRESS_LEVEL_CONFIG to determine the location of the
+ configuration file.
"""
- with config_file.open('r') as fdesc:
- load_address_levels(conn, 'address_levels', json.load(fdesc))
+ cfg = config.load_sub_configuration('', config='ADDRESS_LEVEL_CONFIG')
+ load_address_levels(conn, 'address_levels', cfg)
def create_functions(conn, config, enable_diff_updates=True, enable_debug=False):
NOMINATIM_PHRASE_CONFIG=
# Configuration file for rank assignments.
-# When unset, the internal default settings from 'settings/address-levels.json'
-# are used.
-NOMINATIM_ADDRESS_LEVEL_CONFIG=
+NOMINATIM_ADDRESS_LEVEL_CONFIG=address-levels.json
# Configuration file for OSM data import.
# This may either be the name of one of an internal style or point
mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
- mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_file'),
+ mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_config'),
mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
mock_func_factory(nominatim.tools.refresh, 'setup_website'),
assert func.called == 1
@pytest.mark.parametrize("command,func", [
- ('address-levels', 'load_address_levels_from_file'),
+ ('address-levels', 'load_address_levels_from_config'),
('wiki-data', 'import_wikipedia_articles'),
('importance', 'recompute_importance'),
('website', 'setup_website'),
import pytest
-from nominatim.tools.refresh import load_address_levels, load_address_levels_from_file
+from nominatim.tools.refresh import load_address_levels, load_address_levels_from_config
def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
- load_address_levels_from_file(temp_db_conn, Path(def_config.ADDRESS_LEVEL_CONFIG))
+ load_address_levels_from_config(temp_db_conn, def_config)
assert temp_db_cursor.table_rows('address_levels') > 0
-def test_load_ranks_from_file(temp_db_conn, temp_db_cursor, tmp_path):
- test_file = tmp_path / 'test_levels.json'
+def test_load_ranks_from_project_dir(def_config, temp_db_conn, temp_db_cursor,
+ tmp_path):
+ test_file = tmp_path / 'address-levels.json'
test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
+ def_config.project_dir = tmp_path
- load_address_levels_from_file(temp_db_conn, test_file)
+ load_address_levels_from_config(temp_db_conn, def_config)
- assert temp_db_cursor.table_rows('address_levels') > 0
+ assert temp_db_cursor.table_rows('address_levels') == 1
-def test_load_ranks_from_broken_file(temp_db_conn, tmp_path):
- test_file = tmp_path / 'test_levels.json'
+def test_load_ranks_from_broken_file(def_config, temp_db_conn, tmp_path):
+ test_file = tmp_path / 'address-levels.json'
test_file.write_text('[{"tags":"place":{"sea":2}}}]')
+ def_config.project_dir = tmp_path
with pytest.raises(json.decoder.JSONDecodeError):
- load_address_levels_from_file(temp_db_conn, test_file)
+ load_address_levels_from_config(temp_db_conn, def_config)
def test_load_ranks_country(temp_db_conn, temp_db_cursor):