+++ /dev/null
-if __name__ == '__main__':
- from nominatim import cli
-
- exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))
+++ /dev/null
-# SPDX-License-Identifier: GPL-2.0-only
-#
-# This file is part of Nominatim. (https://nominatim.org)
-#
-# Copyright (C) 2023 by the Nominatim developer community.
-# For a full list of authors see the git log.
-"""
-Subcommand definitions for the command-line tool.
-"""
-# mypy and pylint disagree about the style of explicit exports,
-# see https://github.com/PyCQA/pylint/issues/6006.
-# pylint: disable=useless-import-alias
-
-from nominatim.clicmd.setup import SetupAll as SetupAll
-from nominatim.clicmd.replication import UpdateReplication as UpdateReplication
-from nominatim.clicmd.api import (APISearch as APISearch,
- APIReverse as APIReverse,
- APILookup as APILookup,
- APIDetails as APIDetails,
- APIStatus as APIStatus)
-from nominatim.clicmd.index import UpdateIndex as UpdateIndex
-from nominatim.clicmd.refresh import UpdateRefresh as UpdateRefresh
-from nominatim.clicmd.add_data import UpdateAddData as UpdateAddData
-from nominatim.clicmd.admin import AdminFuncs as AdminFuncs
-from nominatim.clicmd.freeze import SetupFreeze as SetupFreeze
-from nominatim.clicmd.special_phrases import ImportSpecialPhrases as ImportSpecialPhrases
-from nominatim.clicmd.export import QueryExport as QueryExport
-from nominatim.clicmd.convert import ConvertDB as ConvertDB
+++ /dev/null
-# 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.
-"""
-Path settings for extra data used by Nominatim.
-"""
-from pathlib import Path
-
-PHPLIB_DIR = (Path(__file__) / '..' / '..' / 'lib-php').resolve()
-SQLLIB_DIR = (Path(__file__) / '..' / '..' / 'lib-sql').resolve()
-DATA_DIR = (Path(__file__) / '..' / '..' / 'data').resolve()
-CONFIG_DIR = (Path(__file__) / '..' / '..' / 'settings').resolve()
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
The public interface of the Nominatim library.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Extended SQLAlchemy connection class that also includes access to the schema.
import sqlalchemy as sa
from sqlalchemy.ext.asyncio import AsyncConnection
-from nominatim.typing import SaFromClause
-from nominatim.db.sqlalchemy_schema import SearchTables
-from nominatim.db.sqlalchemy_types import Geometry
-from nominatim.api.logging import log
+from nominatim_core.typing import SaFromClause
+from nominatim_core.db.sqlalchemy_schema import SearchTables
+from nominatim_core.db.sqlalchemy_types import Geometry
+from .logging import log
T = TypeVar('T')
class SearchConnection:
""" An extended SQLAlchemy connection class, that also contains
- then table definitions. The underlying asynchronous SQLAlchemy
+ the table definitions. The underlying asynchronous SQLAlchemy
connection can be accessed with the 'connection' property.
The 't' property is the collection of Nominatim tables.
"""
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of classes for API access via libraries.
import sqlalchemy as sa
import sqlalchemy.ext.asyncio as sa_asyncio
-from nominatim.errors import UsageError
-from nominatim.db.sqlalchemy_schema import SearchTables
-from nominatim.db.async_core_library import PGCORE_LIB, PGCORE_ERROR
-import nominatim.db.sqlite_functions
-from nominatim.config import Configuration
-from nominatim.api.connection import SearchConnection
-from nominatim.api.status import get_status, StatusResult
-from nominatim.api.lookup import get_detailed_place, get_simple_place
-from nominatim.api.reverse import ReverseGeocoder
-from nominatim.api.search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer
-import nominatim.api.types as ntyp
-from nominatim.api.results import DetailedResult, ReverseResult, SearchResults
+from nominatim_core.errors import UsageError
+from nominatim_core.db.sqlalchemy_schema import SearchTables
+from nominatim_core.db.async_core_library import PGCORE_LIB, PGCORE_ERROR
+from nominatim_core.config import Configuration
+from .sql import sqlite_functions, sqlalchemy_functions #pylint: disable=unused-import
+from .connection import SearchConnection
+from .status import get_status, StatusResult
+from .lookup import get_detailed_place, get_simple_place
+from .reverse import ReverseGeocoder
+from .search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer
+from . import types as ntyp
+from .results import DetailedResult, ReverseResult, SearchResults
class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
@sa.event.listens_for(engine.sync_engine, "connect")
def _on_sqlite_connect(dbapi_con: Any, _: Any) -> None:
dbapi_con.run_async(lambda conn: conn.enable_load_extension(True))
- nominatim.db.sqlite_functions.install_custom_functions(dbapi_con)
+ sqlite_functions.install_custom_functions(dbapi_con)
cursor = dbapi_con.cursor()
cursor.execute("SELECT load_extension('mod_spatialite')")
cursor.execute('SELECT SetDecimalPrecision(7)')
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for localizing names of results.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for specialised logging with HTML output.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of place lookup by ID.
import sqlalchemy as sa
-from nominatim.typing import SaColumn, SaRow, SaSelect
-from nominatim.api.connection import SearchConnection
-import nominatim.api.types as ntyp
-import nominatim.api.results as nres
-from nominatim.api.logging import log
+from nominatim_core.typing import SaColumn, SaRow, SaSelect
+from .connection import SearchConnection
+from .logging import log
+from . import types as ntyp
+from . import results as nres
RowFunc = Callable[[Optional[SaRow], Type[nres.BaseResultT]], Optional[nres.BaseResultT]]
GeomFunc = Callable[[SaSelect, SaColumn], SaSelect]
-
async def find_in_placex(conn: SearchConnection, place: ntyp.PlaceRef,
add_geometries: GeomFunc) -> Optional[SaRow]:
""" Search for the given place in the placex table and return the
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper classes and functions for formatting results into API responses.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Dataclasses for search results and helper functions to fill them.
import sqlalchemy as sa
-from nominatim.typing import SaSelect, SaRow
-from nominatim.db.sqlalchemy_types import Geometry
-from nominatim.api.types import Point, Bbox, LookupDetails
-from nominatim.api.connection import SearchConnection
-from nominatim.api.logging import log
-from nominatim.api.localization import Locales
+from nominatim_core.typing import SaSelect, SaRow
+from nominatim_core.db.sqlalchemy_types import Geometry
+from .types import Point, Bbox, LookupDetails
+from .connection import SearchConnection
+from .logging import log
+from .localization import Locales
# This file defines complex result data classes.
# pylint: disable=too-many-instance-attributes
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of reverse geocoding.
import sqlalchemy as sa
-from nominatim.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow,\
- SaBind, SaLambdaSelect
-from nominatim.api.connection import SearchConnection
-import nominatim.api.results as nres
-from nominatim.api.logging import log
-from nominatim.api.types import AnyPoint, DataLayer, ReverseDetails, GeometryFormat, Bbox
-from nominatim.db.sqlalchemy_types import Geometry
+from nominatim_core.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow,\
+ SaBind, SaLambdaSelect
+from nominatim_core.db.sqlalchemy_types import Geometry
+from .connection import SearchConnection
+from . import results as nres
+from .logging import log
+from .types import AnyPoint, DataLayer, ReverseDetails, GeometryFormat, Bbox
# In SQLAlchemy expression which compare with NULL need to be expressed with
# the equal sign.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module for forward search.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Conversion from token assignment to an abstract DB search.
from typing import Optional, List, Tuple, Iterator, Dict
import heapq
-from nominatim.api.types import SearchDetails, DataLayer
-from nominatim.api.search.query import QueryStruct, Token, TokenType, TokenRange, BreakType
-from nominatim.api.search.token_assignment import TokenAssignment
-import nominatim.api.search.db_search_fields as dbf
-import nominatim.api.search.db_searches as dbs
-import nominatim.api.search.db_search_lookups as lookups
+from ..types import SearchDetails, DataLayer
+from .query import QueryStruct, Token, TokenType, TokenRange, BreakType
+from .token_assignment import TokenAssignment
+from . import db_search_fields as dbf
+from . import db_searches as dbs
+from . import db_search_lookups as lookups
def wrap_near_search(categories: List[Tuple[str, str]],
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Data structures for more complex fields in abstract search descriptions.
import sqlalchemy as sa
-from nominatim.typing import SaFromClause, SaColumn, SaExpression
-from nominatim.api.search.query import Token
-import nominatim.api.search.db_search_lookups as lookups
-from nominatim.utils.json_writer import JsonWriter
+from nominatim_core.typing import SaFromClause, SaColumn, SaExpression
+from .query import Token
+from . import db_search_lookups as lookups
+from nominatim_core.utils.json_writer import JsonWriter
@dataclasses.dataclass
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of lookup functions for the search_name table.
import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
-from nominatim.typing import SaFromClause
-from nominatim.db.sqlalchemy_types import IntArray
+from nominatim_core.typing import SaFromClause
+from nominatim_core.db.sqlalchemy_types import IntArray
# pylint: disable=consider-using-f-string
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the actual database accesses for forward search.
import sqlalchemy as sa
-from nominatim.typing import SaFromClause, SaScalarSelect, SaColumn, \
- SaExpression, SaSelect, SaLambdaSelect, SaRow, SaBind
-from nominatim.api.connection import SearchConnection
-from nominatim.api.types import SearchDetails, DataLayer, GeometryFormat, Bbox
-import nominatim.api.results as nres
-from nominatim.api.search.db_search_fields import SearchData, WeightedCategories
-from nominatim.db.sqlalchemy_types import Geometry, IntArray
+from nominatim_core.typing import SaFromClause, SaScalarSelect, SaColumn, \
+ SaExpression, SaSelect, SaLambdaSelect, SaRow, SaBind
+from nominatim_core.db.sqlalchemy_types import Geometry, IntArray
+from ..connection import SearchConnection
+from ..types import SearchDetails, DataLayer, GeometryFormat, Bbox
+from .. import results as nres
+from .db_search_fields import SearchData, WeightedCategories
#pylint: disable=singleton-comparison,not-callable
#pylint: disable=too-many-branches,too-many-arguments,too-many-locals,too-many-statements
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Public interface to the search code.
import datetime as dt
import difflib
-from nominatim.api.connection import SearchConnection
-from nominatim.api.types import SearchDetails
-from nominatim.api.results import SearchResult, SearchResults, add_result_details
-from nominatim.api.search.token_assignment import yield_token_assignments
-from nominatim.api.search.db_search_builder import SearchBuilder, build_poi_search, wrap_near_search
-from nominatim.api.search.db_searches import AbstractSearch
-from nominatim.api.search.query_analyzer_factory import make_query_analyzer, AbstractQueryAnalyzer
-from nominatim.api.search.query import Phrase, QueryStruct
-from nominatim.api.logging import log
+from ..connection import SearchConnection
+from ..types import SearchDetails
+from ..results import SearchResult, SearchResults, add_result_details
+from ..logging import log
+from .token_assignment import yield_token_assignments
+from .db_search_builder import SearchBuilder, build_poi_search, wrap_near_search
+from .db_searches import AbstractSearch
+from .query_analyzer_factory import make_query_analyzer, AbstractQueryAnalyzer
+from .query import Phrase, QueryStruct
class ForwardGeocoder:
""" Main class responsible for place search.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of query analysis for the ICU tokenizer.
import sqlalchemy as sa
-from nominatim.typing import SaRow
-from nominatim.api.connection import SearchConnection
-from nominatim.api.logging import log
-from nominatim.api.search import query as qmod
-from nominatim.api.search.query_analyzer_factory import AbstractQueryAnalyzer
-from nominatim.db.sqlalchemy_types import Json
+from nominatim_core.typing import SaRow
+from nominatim_core.db.sqlalchemy_types import Json
+from ..connection import SearchConnection
+from ..logging import log
+from ..search import query as qmod
+from ..search.query_analyzer_factory import AbstractQueryAnalyzer
DB_TO_TOKEN_TYPE = {
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of query analysis for the legacy tokenizer.
import sqlalchemy as sa
-from nominatim.typing import SaRow
-from nominatim.api.connection import SearchConnection
-from nominatim.api.logging import log
-from nominatim.api.search import query as qmod
-from nominatim.api.search.query_analyzer_factory import AbstractQueryAnalyzer
+from nominatim_core.typing import SaRow
+from ..connection import SearchConnection
+from ..logging import log
+from . import query as qmod
+from .query_analyzer_factory import AbstractQueryAnalyzer
def yield_words(terms: List[str], start: int) -> Iterator[Tuple[str, qmod.TokenRange]]:
""" Return all combinations of words in the terms list after the
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Datastructures for a tokenized query.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Factory for creating a query analyzer for the configured tokenizer.
from pathlib import Path
import importlib
-from nominatim.api.logging import log
-from nominatim.api.connection import SearchConnection
+from ..logging import log
+from ..connection import SearchConnection
if TYPE_CHECKING:
- from nominatim.api.search.query import Phrase, QueryStruct
+ from .query import Phrase, QueryStruct
class AbstractQueryAnalyzer(ABC):
""" Class for analysing incoming queries.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Create query interpretations where each vertice in the query is assigned
from typing import Optional, List, Iterator
import dataclasses
-import nominatim.api.search.query as qmod
-from nominatim.api.logging import log
+from ..logging import log
+from . import query as qmod
# pylint: disable=too-many-return-statements,too-many-branches
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Server implementation using the falcon webserver framework.
from falcon.asgi import App, Request, Response
-from nominatim.api import NominatimAPIAsync
-import nominatim.api.v1 as api_impl
-import nominatim.api.logging as loglib
-from nominatim.config import Configuration
+from nominatim_core.config import Configuration
+from ...core import NominatimAPIAsync
+from ... import v1 as api_impl
+from ... import logging as loglib
class HTTPNominatimError(Exception):
""" A special exception class for errors raised during processing.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Server implementation using the starlette webserver framework.
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.middleware.cors import CORSMiddleware
-from nominatim.api import NominatimAPIAsync
-import nominatim.api.v1 as api_impl
-import nominatim.api.logging as loglib
-from nominatim.config import Configuration
+from nominatim_core.config import Configuration
+from ...core import NominatimAPIAsync
+from ... import v1 as api_impl
+from ... import logging as loglib
class ParamWrapper(api_impl.ASGIAdaptor):
""" Adaptor class for server glue to Starlette framework.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom functions and expressions for SQLAlchemy.
import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
-from nominatim.typing import SaColumn
+from nominatim_core.typing import SaColumn
# pylint: disable=all
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom functions for SQLite.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Classes and function related to status call.
import sqlalchemy as sa
-from nominatim.api.connection import SearchConnection
-from nominatim import version
+from .connection import SearchConnection
+from .version import NOMINATIM_API_VERSION
@dataclasses.dataclass
class StatusResult:
"""
status: int
message: str
- software_version = version.NOMINATIM_VERSION
+ software_version = NOMINATIM_API_VERSION
data_updated: Optional[dt.datetime] = None
- database_version: Optional[version.NominatimVersion] = None
+ database_version: Optional[str] = None
async def get_status(conn: SearchConnection) -> StatusResult:
# Database version
try:
- verstr = await conn.get_property('database_version')
- status.database_version = version.parse_version(verstr)
+ status.database_version = await conn.get_property('database_version')
except ValueError:
pass
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Complex datatypes used by the Nominatim API.
from struct import unpack
from binascii import unhexlify
-from nominatim.errors import UsageError
-from nominatim.api.localization import Locales
+from nominatim_core.errors import UsageError
+from .localization import Locales
# pylint: disable=no-member,too-many-boolean-expressions,too-many-instance-attributes
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of API version v1 (aka the legacy version).
#pylint: disable=useless-import-alias
-from nominatim.api.v1.server_glue import (ASGIAdaptor as ASGIAdaptor,
- EndpointFunc as EndpointFunc,
- ROUTES as ROUTES)
+from .server_glue import (ASGIAdaptor as ASGIAdaptor,
+ EndpointFunc as EndpointFunc,
+ ROUTES as ROUTES)
-import nominatim.api.v1.format as _format
+from . import format as _format
list_formats = _format.dispatch.list_formats
supports_format = _format.dispatch.supports_format
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Hard-coded information about tag categories.
"""
from typing import Tuple, Optional, Mapping, Union
-import nominatim.api as napi
+from ..results import ReverseResult, SearchResult
+from ..types import Bbox
def get_label_tag(category: Tuple[str, str], extratags: Optional[Mapping[str, str]],
rank: int, country: Optional[str]) -> str:
return label.lower().replace(' ', '_')
-def bbox_from_result(result: Union[napi.ReverseResult, napi.SearchResult]) -> napi.Bbox:
+def bbox_from_result(result: Union[ReverseResult, SearchResult]) -> Bbox:
""" Compute a bounding box for the result. For ways and relations
a given boundingbox is used. For all other object, a box is computed
around the centroid according to dimensions derived from the
"""
if (result.osm_object and result.osm_object[0] == 'N') or result.bbox is None:
extent = NODE_EXTENT.get(result.category, 0.00005)
- return napi.Bbox.from_point(result.centroid, extent)
+ return Bbox.from_point(result.centroid, extent)
return result.bbox
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Output formatters for API version v1.
import collections
import datetime as dt
-import nominatim.api as napi
-from nominatim.api.result_formatting import FormatDispatcher
-from nominatim.api.v1.classtypes import ICONS
-from nominatim.api.v1 import format_json, format_xml
-from nominatim.utils.json_writer import JsonWriter
+from nominatim_core.utils.json_writer import JsonWriter
+from ..status import StatusResult
+from ..results import DetailedResult, ReverseResults, SearchResults, \
+ AddressLines, AddressLine
+from ..localization import Locales
+from ..result_formatting import FormatDispatcher
+from .classtypes import ICONS
+from . import format_json, format_xml
class RawDataList(List[Dict[str, Any]]):
""" Data type for formatting raw data lists 'as is' in json.
dispatch = FormatDispatcher()
-@dispatch.format_func(napi.StatusResult, 'text')
-def _format_status_text(result: napi.StatusResult, _: Mapping[str, Any]) -> str:
+@dispatch.format_func(StatusResult, 'text')
+def _format_status_text(result: StatusResult, _: Mapping[str, Any]) -> str:
if result.status:
return f"ERROR: {result.message}"
return 'OK'
-@dispatch.format_func(napi.StatusResult, 'json')
-def _format_status_json(result: napi.StatusResult, _: Mapping[str, Any]) -> str:
+@dispatch.format_func(StatusResult, 'json')
+def _format_status_json(result: StatusResult, _: Mapping[str, Any]) -> str:
out = JsonWriter()
out.start_object()\
return out()
-def _add_address_row(writer: JsonWriter, row: napi.AddressLine,
- locales: napi.Locales) -> None:
+def _add_address_row(writer: JsonWriter, row: AddressLine,
+ locales: Locales) -> None:
writer.start_object()\
.keyval('localname', locales.display_name(row.names))\
.keyval_not_none('place_id', row.place_id)
.end_object()
-def _add_address_rows(writer: JsonWriter, section: str, rows: napi.AddressLines,
- locales: napi.Locales) -> None:
+def _add_address_rows(writer: JsonWriter, section: str, rows: AddressLines,
+ locales: Locales) -> None:
writer.key(section).start_array()
for row in rows:
_add_address_row(writer, row, locales)
writer.end_array().next()
-def _add_parent_rows_grouped(writer: JsonWriter, rows: napi.AddressLines,
- locales: napi.Locales) -> None:
+def _add_parent_rows_grouped(writer: JsonWriter, rows: AddressLines,
+ locales: Locales) -> None:
# group by category type
data = collections.defaultdict(list)
for row in rows:
writer.end_object().next()
-@dispatch.format_func(napi.DetailedResult, 'json')
-def _format_details_json(result: napi.DetailedResult, options: Mapping[str, Any]) -> str:
- locales = options.get('locales', napi.Locales())
+@dispatch.format_func(DetailedResult, 'json')
+def _format_details_json(result: DetailedResult, options: Mapping[str, Any]) -> str:
+ locales = options.get('locales', Locales())
geom = result.geometry.get('geojson')
centroid = result.centroid.to_geojson()
return out()
-@dispatch.format_func(napi.ReverseResults, 'xml')
-def _format_reverse_xml(results: napi.ReverseResults, options: Mapping[str, Any]) -> str:
+@dispatch.format_func(ReverseResults, 'xml')
+def _format_reverse_xml(results: ReverseResults, options: Mapping[str, Any]) -> str:
return format_xml.format_base_xml(results,
options, True, 'reversegeocode',
{'querystring': options.get('query', '')})
-@dispatch.format_func(napi.ReverseResults, 'geojson')
-def _format_reverse_geojson(results: napi.ReverseResults,
+@dispatch.format_func(ReverseResults, 'geojson')
+def _format_reverse_geojson(results: ReverseResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_geojson(results, options, True)
-@dispatch.format_func(napi.ReverseResults, 'geocodejson')
-def _format_reverse_geocodejson(results: napi.ReverseResults,
+@dispatch.format_func(ReverseResults, 'geocodejson')
+def _format_reverse_geocodejson(results: ReverseResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_geocodejson(results, options, True)
-@dispatch.format_func(napi.ReverseResults, 'json')
-def _format_reverse_json(results: napi.ReverseResults,
+@dispatch.format_func(ReverseResults, 'json')
+def _format_reverse_json(results: ReverseResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, True,
class_label='class')
-@dispatch.format_func(napi.ReverseResults, 'jsonv2')
-def _format_reverse_jsonv2(results: napi.ReverseResults,
+@dispatch.format_func(ReverseResults, 'jsonv2')
+def _format_reverse_jsonv2(results: ReverseResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, True,
class_label='category')
-@dispatch.format_func(napi.SearchResults, 'xml')
-def _format_search_xml(results: napi.SearchResults, options: Mapping[str, Any]) -> str:
+@dispatch.format_func(SearchResults, 'xml')
+def _format_search_xml(results: SearchResults, options: Mapping[str, Any]) -> str:
extra = {'querystring': options.get('query', '')}
for attr in ('more_url', 'exclude_place_ids', 'viewbox'):
if options.get(attr):
-@dispatch.format_func(napi.SearchResults, 'geojson')
-def _format_search_geojson(results: napi.SearchResults,
+@dispatch.format_func(SearchResults, 'geojson')
+def _format_search_geojson(results: SearchResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_geojson(results, options, False)
-@dispatch.format_func(napi.SearchResults, 'geocodejson')
-def _format_search_geocodejson(results: napi.SearchResults,
+@dispatch.format_func(SearchResults, 'geocodejson')
+def _format_search_geocodejson(results: SearchResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_geocodejson(results, options, False)
-@dispatch.format_func(napi.SearchResults, 'json')
-def _format_search_json(results: napi.SearchResults,
+@dispatch.format_func(SearchResults, 'json')
+def _format_search_json(results: SearchResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, False,
class_label='class')
-@dispatch.format_func(napi.SearchResults, 'jsonv2')
-def _format_search_jsonv2(results: napi.SearchResults,
+@dispatch.format_func(SearchResults, 'jsonv2')
+def _format_search_jsonv2(results: SearchResults,
options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, False,
class_label='category')
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for output of results in json formats.
"""
from typing import Mapping, Any, Optional, Tuple, Union
-import nominatim.api as napi
-import nominatim.api.v1.classtypes as cl
-from nominatim.utils.json_writer import JsonWriter
+from nominatim_core.utils.json_writer import JsonWriter
+from ..results import AddressLines, ReverseResults, SearchResults
+from . import classtypes as cl
#pylint: disable=too-many-branches
.keyval('osm_id', osm_object[1])
-def _write_typed_address(out: JsonWriter, address: Optional[napi.AddressLines],
+def _write_typed_address(out: JsonWriter, address: Optional[AddressLines],
country_code: Optional[str]) -> None:
parts = {}
for line in (address or []):
def _write_geocodejson_address(out: JsonWriter,
- address: Optional[napi.AddressLines],
+ address: Optional[AddressLines],
obj_place_id: Optional[int],
country_code: Optional[str]) -> None:
extra = {}
out.keyval('country_code', country_code)
-def format_base_json(results: Union[napi.ReverseResults, napi.SearchResults],
+def format_base_json(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any], simple: bool,
class_label: str) -> str:
""" Return the result list as a simple json string in custom Nominatim format.
return out()
-def format_base_geojson(results: Union[napi.ReverseResults, napi.SearchResults],
+def format_base_geojson(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any],
simple: bool) -> str:
""" Return the result list as a geojson string.
return out()
-def format_base_geocodejson(results: Union[napi.ReverseResults, napi.SearchResults],
+def format_base_geocodejson(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any], simple: bool) -> str:
""" Return the result list as a geocodejson string.
"""
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for output of results in XML format.
import datetime as dt
import xml.etree.ElementTree as ET
-import nominatim.api as napi
-import nominatim.api.v1.classtypes as cl
+from ..results import AddressLines, ReverseResult, ReverseResults, \
+ SearchResult, SearchResults
+from . import classtypes as cl
#pylint: disable=too-many-branches
-def _write_xml_address(root: ET.Element, address: napi.AddressLines,
+def _write_xml_address(root: ET.Element, address: AddressLines,
country_code: Optional[str]) -> None:
parts = {}
for line in address:
ET.SubElement(root, 'country_code').text = country_code
-def _create_base_entry(result: Union[napi.ReverseResult, napi.SearchResult],
+def _create_base_entry(result: Union[ReverseResult, SearchResult],
root: ET.Element, simple: bool) -> ET.Element:
place = ET.SubElement(root, 'result' if simple else 'place')
if result.place_id is not None:
return place
-def format_base_xml(results: Union[napi.ReverseResults, napi.SearchResults],
+def format_base_xml(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any],
simple: bool, xml_root_tag: str,
xml_extra_info: Mapping[str, str]) -> str:
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper function for parsing parameters and and outputting data
from itertools import chain
import re
-from nominatim.api.results import SearchResult, SearchResults, SourceTable
-from nominatim.api.types import SearchDetails, GeometryFormat
+from ..results import SearchResult, SearchResults, SourceTable
+from ..types import SearchDetails, GeometryFormat
REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea
4, 4, # 3-4 Country
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Generic part of the server implementation of the v1 API.
import sqlalchemy as sa
-from nominatim.errors import UsageError
-from nominatim.config import Configuration
-import nominatim.api as napi
-import nominatim.api.logging as loglib
-from nominatim.api.v1.format import dispatch as formatting
-from nominatim.api.v1.format import RawDataList
-from nominatim.api.v1 import helpers
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from .. import logging as loglib
+from ..core import NominatimAPIAsync
+from .format import dispatch as formatting
+from .format import RawDataList
+from ..types import DataLayer, GeometryFormat, PlaceRef, PlaceID, OsmID, Point
+from ..status import StatusResult
+from ..results import DetailedResult, ReverseResults, SearchResult, SearchResults
+from ..localization import Locales
+from . import helpers
CONTENT_TEXT = 'text/plain; charset=utf-8'
CONTENT_XML = 'text/xml; charset=utf-8'
return False
- def get_layers(self) -> Optional[napi.DataLayer]:
+ def get_layers(self) -> Optional[DataLayer]:
""" Return a parsed version of the layer parameter.
"""
param = self.get('layer', None)
if param is None:
return None
- return cast(napi.DataLayer,
- reduce(napi.DataLayer.__or__,
- (getattr(napi.DataLayer, s.upper()) for s in param.split(','))))
+ return cast(DataLayer,
+ reduce(DataLayer.__or__,
+ (getattr(DataLayer, s.upper()) for s in param.split(','))))
def parse_format(self, result_type: Type[Any], default: str) -> str:
""" Create details structure from the supplied geometry parameters.
"""
numgeoms = 0
- output = napi.GeometryFormat.NONE
+ output = GeometryFormat.NONE
if self.get_bool('polygon_geojson', False):
- output |= napi.GeometryFormat.GEOJSON
+ output |= GeometryFormat.GEOJSON
numgeoms += 1
if fmt not in ('geojson', 'geocodejson'):
if self.get_bool('polygon_text', False):
- output |= napi.GeometryFormat.TEXT
+ output |= GeometryFormat.TEXT
numgeoms += 1
if self.get_bool('polygon_kml', False):
- output |= napi.GeometryFormat.KML
+ output |= GeometryFormat.KML
numgeoms += 1
if self.get_bool('polygon_svg', False):
- output |= napi.GeometryFormat.SVG
+ output |= GeometryFormat.SVG
numgeoms += 1
if numgeoms > self.config().get_int('POLYGON_OUTPUT_MAX_TYPES'):
}
-async def status_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def status_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /status endpoint. See API docs for details.
"""
result = await api.status()
- fmt = params.parse_format(napi.StatusResult, 'text')
+ fmt = params.parse_format(StatusResult, 'text')
if fmt == 'text' and result.status:
status_code = 500
status=status_code)
-async def details_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def details_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /details endpoint. See API docs for details.
"""
- fmt = params.parse_format(napi.DetailedResult, 'json')
+ fmt = params.parse_format(DetailedResult, 'json')
place_id = params.get_int('place_id', 0)
- place: napi.PlaceRef
+ place: PlaceRef
if place_id:
- place = napi.PlaceID(place_id)
+ place = PlaceID(place_id)
else:
osmtype = params.get('osmtype')
if osmtype is None:
params.raise_error("Missing ID parameter 'place_id' or 'osmtype'.")
- place = napi.OsmID(osmtype, params.get_int('osmid'), params.get('class'))
+ place = OsmID(osmtype, params.get_int('osmid'), params.get('class'))
debug = params.setup_debugging()
- locales = napi.Locales.from_accept_languages(params.get_accepted_languages())
+ locales = Locales.from_accept_languages(params.get_accepted_languages())
result = await api.details(place,
address_details=params.get_bool('addressdetails', False),
linked_places=params.get_bool('linkedplaces', True),
parented_places=params.get_bool('hierarchy', False),
keywords=params.get_bool('keywords', False),
- geometry_output = napi.GeometryFormat.GEOJSON
+ geometry_output = GeometryFormat.GEOJSON
if params.get_bool('polygon_geojson', False)
- else napi.GeometryFormat.NONE,
+ else GeometryFormat.NONE,
locales=locales
)
return params.build_response(output, num_results=1)
-async def reverse_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def reverse_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /reverse endpoint. See API docs for details.
"""
- fmt = params.parse_format(napi.ReverseResults, 'xml')
+ fmt = params.parse_format(ReverseResults, 'xml')
debug = params.setup_debugging()
- coord = napi.Point(params.get_float('lon'), params.get_float('lat'))
+ coord = Point(params.get_float('lon'), params.get_float('lat'))
details = params.parse_geometry_details(fmt)
details['max_rank'] = helpers.zoom_to_rank(params.get_int('zoom', 18))
details['layers'] = params.get_layers()
- details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
+ details['locales'] = Locales.from_accept_languages(params.get_accepted_languages())
result = await api.reverse(coord, **details)
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)}
- output = formatting.format_result(napi.ReverseResults([result] if result else []),
+ output = formatting.format_result(ReverseResults([result] if result else []),
fmt, fmt_options)
return params.build_response(output, num_results=1 if result else 0)
-async def lookup_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def lookup_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /lookup endpoint. See API docs for details.
"""
- fmt = params.parse_format(napi.SearchResults, 'xml')
+ fmt = params.parse_format(SearchResults, 'xml')
debug = params.setup_debugging()
details = params.parse_geometry_details(fmt)
- details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
+ details['locales'] = Locales.from_accept_languages(params.get_accepted_languages())
places = []
for oid in (params.get('osm_ids') or '').split(','):
oid = oid.strip()
if len(oid) > 1 and oid[0] in 'RNWrnw' and oid[1:].isdigit():
- places.append(napi.OsmID(oid[0].upper(), int(oid[1:])))
+ places.append(OsmID(oid[0].upper(), int(oid[1:])))
if len(places) > params.config().get_int('LOOKUP_MAX_COUNT'):
params.raise_error('Too many object IDs.')
if places:
results = await api.lookup(places, **details)
else:
- results = napi.SearchResults()
+ results = SearchResults()
if debug:
return params.build_response(loglib.get_and_disable(), num_results=len(results))
return params.build_response(output, num_results=len(results))
-async def _unstructured_search(query: str, api: napi.NominatimAPIAsync,
- details: Dict[str, Any]) -> napi.SearchResults:
+async def _unstructured_search(query: str, api: NominatimAPIAsync,
+ details: Dict[str, Any]) -> SearchResults:
if not query:
- return napi.SearchResults()
+ return SearchResults()
# Extract special format for coordinates from query.
query, x, y = helpers.extract_coords_from_query(query)
if x is not None:
assert y is not None
- details['near'] = napi.Point(x, y)
+ details['near'] = Point(x, y)
details['near_radius'] = 0.1
# If no query is left, revert to reverse search.
if x is not None and not query:
result = await api.reverse(details['near'], **details)
if not result:
- return napi.SearchResults()
+ return SearchResults()
- return napi.SearchResults(
- [napi.SearchResult(**{f.name: getattr(result, f.name)
- for f in dataclasses.fields(napi.SearchResult)
- if hasattr(result, f.name)})])
+ return SearchResults(
+ [SearchResult(**{f.name: getattr(result, f.name)
+ for f in dataclasses.fields(SearchResult)
+ if hasattr(result, f.name)})])
query, cls, typ = helpers.extract_category_from_query(query)
if cls is not None:
return await api.search(query, **details)
-async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def search_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /search endpoint. See API docs for details.
"""
- fmt = params.parse_format(napi.SearchResults, 'jsonv2')
+ fmt = params.parse_format(SearchResults, 'jsonv2')
debug = params.setup_debugging()
details = params.parse_geometry_details(fmt)
details['min_rank'], details['max_rank'] = \
helpers.feature_type_to_rank(params.get('featureType', ''))
if params.get('featureType', None) is not None:
- details['layers'] = napi.DataLayer.ADDRESS
+ details['layers'] = DataLayer.ADDRESS
else:
details['layers'] = params.get_layers()
- details['locales'] = napi.Locales.from_accept_languages(params.get_accepted_languages())
+ details['locales'] = Locales.from_accept_languages(params.get_accepted_languages())
# unstructured query parameters
query = params.get('q', None)
return params.build_response(output, num_results=len(results))
-async def deletable_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def deletable_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /deletable endpoint.
This is a special endpoint that shows polygons that have been
deleted or are broken in the OSM data but are kept in the
return params.build_response(formatting.format_result(results, fmt, {}))
-async def polygons_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> Any:
+async def polygons_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
""" Server glue for /polygons endpoint.
This is a special endpoint that shows polygons that have changed
their size but are kept in the Nominatim database with their
return params.build_response(formatting.format_result(results, fmt, {}))
-EndpointFunc = Callable[[napi.NominatimAPIAsync, ASGIAdaptor], Any]
+EndpointFunc = Callable[[NominatimAPIAsync, ASGIAdaptor], Any]
ROUTES = [
('status', status_endpoint),
--- /dev/null
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Version information for the Nominatim API.
+"""
+
+NOMINATIM_API_VERSION = '4.4.99'
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
from dotenv import dotenv_values
from psycopg2.extensions import parse_dsn
-from nominatim.typing import StrPath
-from nominatim.errors import UsageError
-import nominatim.paths
+from .typing import StrPath
+from .errors import UsageError
+from . import paths
LOG = logging.getLogger()
CONFIG_CACHE : Dict[str, Any] = {}
environ: Optional[Mapping[str, str]] = None) -> None:
self.environ = environ or os.environ
self.project_dir = project_dir
- self.config_dir = nominatim.paths.CONFIG_DIR
+ self.config_dir = paths.CONFIG_DIR
self._config = dotenv_values(str(self.config_dir / 'env.defaults'))
if self.project_dir is not None and (self.project_dir / '.env').is_file():
self.project_dir = self.project_dir.resolve()
class _LibDirs:
module: Path
osm2pgsql: Path
- php = nominatim.paths.PHPLIB_DIR
- sql = nominatim.paths.SQLLIB_DIR
- data = nominatim.paths.DATA_DIR
+ php = paths.PHPLIB_DIR
+ sql = paths.SQLLIB_DIR
+ data = paths.DATA_DIR
self.lib_dir = _LibDirs()
self._private_plugins: Dict[str, object] = {}
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
""" Non-blocking database connections.
"""
except ImportError:
__has_psycopg2_errors__ = False
-from nominatim.typing import T_cursor, Query
+from ..typing import T_cursor, Query
LOG = logging.getLogger()
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Import the base library to use with asynchronous SQLAlchemy.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Specialised connection and cursor functions.
import psycopg2.extras
from psycopg2 import sql as pysql
-from nominatim.typing import SysEnv, Query, T_cursor
-from nominatim.errors import UsageError
+from ..typing import SysEnv, Query, T_cursor
+from ..errors import UsageError
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Query and access functions for the in-database property table.
"""
from typing import Optional, cast
-from nominatim.db.connection import Connection
+from .connection import Connection
def set_property(conn: Connection, name: str, value: str) -> None:
""" Add or replace the property with the given name.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Preprocessing of SQL files.
from typing import Set, Dict, Any, cast
import jinja2
-from nominatim.db.connection import Connection
-from nominatim.db.async_connection import WorkerPool
-from nominatim.config import Configuration
+from .connection import Connection
+from .async_connection import WorkerPool
+from ..config import Configuration
def _get_partitions(conn: Connection) -> Set[int]:
""" Get the set of partitions currently in use.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
SQLAlchemy definitions for all tables used by the frontend.
"""
import sqlalchemy as sa
-import nominatim.db.sqlalchemy_functions #pylint: disable=unused-import
-from nominatim.db.sqlalchemy_types import Geometry, KeyValueStore, IntArray
+from .sqlalchemy_types import Geometry, KeyValueStore, IntArray
#pylint: disable=too-many-instance-attributes
class SearchTables:
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module with custom types for SQLAlchemy
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom types for SQLAlchemy.
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import types
-from nominatim.typing import SaColumn, SaBind
+from ...typing import SaColumn, SaBind
#pylint: disable=all
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom type for an array of integers.
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql import ARRAY
-from nominatim.typing import SaDialect, SaColumn
+from ...typing import SaDialect, SaColumn
# pylint: disable=all
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Common json type for different dialects.
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.sqlite import JSON as sqlite_json
-from nominatim.typing import SaDialect
+from ...typing import SaDialect
# pylint: disable=all
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
A custom type that implements a simple key-value store of strings.
from sqlalchemy.dialects.postgresql import HSTORE
from sqlalchemy.dialects.sqlite import JSON as sqlite_json
-from nominatim.typing import SaDialect, SaColumn
+from ...typing import SaDialect, SaColumn
# pylint: disable=all
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Access and helper functions for the status and status log table.
import logging
import re
-from nominatim.db.connection import Connection
-from nominatim.tools.exec_utils import get_url
-from nominatim.errors import UsageError
-from nominatim.typing import TypedDict
+from .connection import Connection
+from ..utils.url_utils import get_url
+from ..errors import UsageError
+from ..typing import TypedDict
LOG = logging.getLogger()
ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for handling DB accesses.
import io
from pathlib import Path
-from nominatim.db.connection import get_pg_env, Cursor
-from nominatim.errors import UsageError
+from .connection import get_pg_env, Cursor
+from ..errors import UsageError
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom exception and error classes for Nominatim.
--- /dev/null
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Path settings for extra data used by Nominatim.
+"""
+from pathlib import Path
+
+PHPLIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-php').resolve()
+SQLLIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-sql').resolve()
+DATA_DIR = (Path(__file__) / '..' / '..' / '..' / 'data').resolve()
+CONFIG_DIR = (Path(__file__) / '..' / '..' / '..' / 'settings').resolve()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Type definitions for typing annotations.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for computation of centroids.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Streaming JSON encoder.
--- /dev/null
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Helper functions for accessing URL.
+"""
+from typing import IO
+import logging
+import urllib.request as urlrequest
+
+from ..version import NOMINATIM_CORE_VERSION
+
+LOG = logging.getLogger()
+
+def get_url(url: str) -> str:
+ """ Get the contents from the given URL and return it as a UTF-8 string.
+
+ This version makes sure that an appropriate user agent is sent.
+ """
+ headers = {"User-Agent": f"Nominatim/{NOMINATIM_CORE_VERSION!s}"}
+
+ try:
+ request = urlrequest.Request(url, headers=headers)
+ with urlrequest.urlopen(request) as response: # type: IO[bytes]
+ return response.read().decode('utf-8')
+ except Exception:
+ LOG.fatal('Failed to load URL: %s', url)
+ raise
--- /dev/null
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Version information for the Nominatim core package.
+"""
+
+NOMINATIM_CORE_VERSION = '4.4.99'
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Command-line interface to the Nominatim functions for import, update,
import argparse
from pathlib import Path
-from nominatim.config import Configuration
-from nominatim.tools.exec_utils import run_php_server
-from nominatim.errors import UsageError
-from nominatim import clicmd
-from nominatim import version
-from nominatim.clicmd.args import NominatimArgs, Subcommand
+from nominatim_core.config import Configuration
+from nominatim_core.errors import UsageError
+from .tools.exec_utils import run_php_server
+from . import clicmd
+from . import version
+from .clicmd.args import NominatimArgs, Subcommand
LOG = logging.getLogger()
--- /dev/null
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2023 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Subcommand definitions for the command-line tool.
+"""
+# mypy and pylint disagree about the style of explicit exports,
+# see https://github.com/PyCQA/pylint/issues/6006.
+# pylint: disable=useless-import-alias
+
+from .setup import SetupAll as SetupAll
+from .replication import UpdateReplication as UpdateReplication
+from .api import (APISearch as APISearch,
+ APIReverse as APIReverse,
+ APILookup as APILookup,
+ APIDetails as APIDetails,
+ APIStatus as APIStatus)
+from .index import UpdateIndex as UpdateIndex
+from .refresh import UpdateRefresh as UpdateRefresh
+from .add_data import UpdateAddData as UpdateAddData
+from .admin import AdminFuncs as AdminFuncs
+from .freeze import SetupFreeze as SetupFreeze
+from .special_phrases import ImportSpecialPhrases as ImportSpecialPhrases
+from .export import QueryExport as QueryExport
+from .convert import ConvertDB as ConvertDB
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'add-data' subcommand.
import psutil
-from nominatim.clicmd.args import NominatimArgs
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
def run(self, args: NominatimArgs) -> int:
- from nominatim.tokenizer import factory as tokenizer_factory
- from nominatim.tools import tiger_data, add_osm_data
+ from ..tokenizer import factory as tokenizer_factory
+ from ..tools import tiger_data, add_osm_data
if args.tiger_data:
tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'admin' subcommand.
import argparse
import random
-from nominatim.db.connection import connect
-from nominatim.clicmd.args import NominatimArgs
-import nominatim.api as napi
+import nominatim_api as napi
+from nominatim_core.db.connection import connect
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Subcommand definitions for API calls from the command line.
import json
import sys
-from nominatim.clicmd.args import NominatimArgs
-import nominatim.api as napi
-import nominatim.api.v1 as api_output
-from nominatim.api.v1.helpers import zoom_to_rank, deduplicate_results
-from nominatim.api.v1.format import dispatch as formatting
-import nominatim.api.logging as loglib
+import nominatim_api as napi
+import nominatim_api.v1 as api_output
+from nominatim_api.v1.helpers import zoom_to_rank, deduplicate_results
+from nominatim_api.v1.format import dispatch as formatting
+import nominatim_api.logging as loglib
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Provides custom functions over command-line arguments.
from functools import reduce
from pathlib import Path
-from nominatim.errors import UsageError
-from nominatim.config import Configuration
-from nominatim.typing import Protocol
-import nominatim.api as napi
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from nominatim_core.typing import Protocol
+import nominatim_api as napi
LOG = logging.getLogger()
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'convert' subcommand.
import asyncio
from pathlib import Path
-from nominatim.clicmd.args import NominatimArgs
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'export' subcommand.
import sqlalchemy as sa
-from nominatim.clicmd.args import NominatimArgs
-import nominatim.api as napi
-from nominatim.api.results import create_from_placex_row, ReverseResult, add_result_details
-from nominatim.api.types import LookupDetails
-from nominatim.errors import UsageError
+import nominatim_api as napi
+from nominatim_api.results import create_from_placex_row, ReverseResult, add_result_details
+from nominatim_api.types import LookupDetails
+from nominatim_core.errors import UsageError
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'freeze' subcommand.
"""
import argparse
-from nominatim.db.connection import connect
-from nominatim.clicmd.args import NominatimArgs
+from nominatim_core.db.connection import connect
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'index' subcommand.
import psutil
-from nominatim.db import status
-from nominatim.db.connection import connect
-from nominatim.clicmd.args import NominatimArgs
+from nominatim_core.db import status
+from nominatim_core.db.connection import connect
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of 'refresh' subcommand.
import logging
from pathlib import Path
-from nominatim.config import Configuration
-from nominatim.db.connection import connect
-from nominatim.tokenizer.base import AbstractTokenizer
-from nominatim.clicmd.args import NominatimArgs
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect
+from ..tokenizer.base import AbstractTokenizer
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'replication' sub-command.
import socket
import time
-from nominatim.db import status
-from nominatim.db.connection import connect
-from nominatim.errors import UsageError
-from nominatim.clicmd.args import NominatimArgs
+from nominatim_core.db import status
+from nominatim_core.db.connection import connect
+from nominatim_core.errors import UsageError
+from .args import NominatimArgs
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'import' subcommand.
import psutil
-from nominatim.config import Configuration
-from nominatim.db.connection import connect
-from nominatim.db import status, properties
-from nominatim.tokenizer.base import AbstractTokenizer
-from nominatim.version import NOMINATIM_VERSION
-from nominatim.clicmd.args import NominatimArgs
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect
+from nominatim_core.db import status, properties
+from ..tokenizer.base import AbstractTokenizer
+from ..version import NOMINATIM_VERSION
+from .args import NominatimArgs
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Implementation of the 'special-phrases' command.
import logging
from pathlib import Path
-from nominatim.errors import UsageError
-from nominatim.db.connection import connect
-from nominatim.tools.special_phrases.sp_importer import SPImporter, SpecialPhraseLoader
-from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
-from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
-from nominatim.clicmd.args import NominatimArgs
+from nominatim_core.errors import UsageError
+from nominatim_core.db.connection import connect
+from ..tools.special_phrases.sp_importer import SPImporter, SpecialPhraseLoader
+from ..tools.special_phrases.sp_wiki_loader import SPWikiLoader
+from ..tools.special_phrases.sp_csv_loader import SPCsvLoader
+from .args import NominatimArgs
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for importing and managing static country information.
from pathlib import Path
import psycopg2.extras
-from nominatim.db import utils as db_utils
-from nominatim.db.connection import connect, Connection
-from nominatim.errors import UsageError
-from nominatim.config import Configuration
-from nominatim.tokenizer.base import AbstractTokenizer
+from nominatim_core.db import utils as db_utils
+from nominatim_core.db.connection import connect, Connection
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from ..tokenizer.base import AbstractTokenizer
def _flatten_name_list(names: Any) -> Dict[str, str]:
if names is None:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Wrapper around place information the indexer gets from the database and hands to
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Data class for a single name of a place.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for formatting postcodes according to their country-specific
from typing import Any, Mapping, Optional, Set, Match
import re
-from nominatim.errors import UsageError
-from nominatim.data import country_info
+from nominatim_core.errors import UsageError
+from . import country_info
class CountryPostcodeMatcher:
""" Matches and formats a postcode according to a format definition
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Main work horse for indexing (computing addresses) the database.
import psycopg2.extras
-from nominatim.tokenizer.base import AbstractTokenizer
-from nominatim.indexer.progress import ProgressLogger
-from nominatim.indexer import runners
-from nominatim.db.async_connection import DBConnection, WorkerPool
-from nominatim.db.connection import connect, Connection, Cursor
-from nominatim.typing import DictCursorResults
+from nominatim_core.typing import DictCursorResults
+from nominatim_core.db.async_connection import DBConnection, WorkerPool
+from nominatim_core.db.connection import connect, Connection, Cursor
+from ..tokenizer.base import AbstractTokenizer
+from .progress import ProgressLogger
+from . import runners
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helpers for progress logging.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Mix-ins that provide the actual commands for the indexer for various indexing
from psycopg2 import sql as pysql
import psycopg2.extras
-from nominatim.data.place_info import PlaceInfo
-from nominatim.tokenizer.base import AbstractAnalyzer
-from nominatim.db.async_connection import DBConnection
-from nominatim.typing import Query, DictCursorResult, DictCursorResults, Protocol
+from nominatim_core.typing import Query, DictCursorResult, DictCursorResults, Protocol
+from nominatim_core.db.async_connection import DBConnection
+from ..data.place_info import PlaceInfo
+from ..tokenizer.base import AbstractAnalyzer
# pylint: disable=C0111
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Abstract class definitions for tokenizers. These base classes are here
from typing import List, Tuple, Dict, Any, Optional, Iterable
from pathlib import Path
-from nominatim.config import Configuration
-from nominatim.db.connection import Connection
-from nominatim.data.place_info import PlaceInfo
-from nominatim.typing import Protocol
+from nominatim_core.typing import Protocol
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import Connection
+from ..data.place_info import PlaceInfo
class AbstractAnalyzer(ABC):
""" The analyzer provides the functions for analysing names and building
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for creating a tokenizer or initialising the right one for an
import importlib
from pathlib import Path
-from nominatim.errors import UsageError
-from nominatim.db import properties
-from nominatim.db.connection import connect
-from nominatim.config import Configuration
-from nominatim.tokenizer.base import AbstractTokenizer, TokenizerModule
+from nominatim_core.errors import UsageError
+from nominatim_core.db import properties
+from nominatim_core.db.connection import connect
+from nominatim_core.config import Configuration
+from ..tokenizer.base import AbstractTokenizer, TokenizerModule
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper class to create ICU rules from a configuration file.
from icu import Transliterator
-from nominatim.config import flatten_config_list, Configuration
-from nominatim.db.properties import set_property, get_property
-from nominatim.db.connection import Connection
-from nominatim.errors import UsageError
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis
-from nominatim.tokenizer.token_analysis.base import AnalysisModule, Analyzer
-import nominatim.data.country_info
+from nominatim_core.config import flatten_config_list, Configuration
+from nominatim_core.db.properties import set_property, get_property
+from nominatim_core.db.connection import Connection
+from nominatim_core.errors import UsageError
+from .place_sanitizer import PlaceSanitizer
+from .icu_token_analysis import ICUTokenAnalysis
+from .token_analysis.base import AnalysisModule, Analyzer
+from ..data import country_info
LOG = logging.getLogger()
config='TOKENIZER_CONFIG')
# Make sure country information is available to analyzers and sanitizers.
- nominatim.data.country_info.setup_country_config(config)
+ country_info.setup_country_config(config)
self.normalization_rules = self._cfg_to_icu_rules(rules, 'normalization')
self.transliteration_rules = self._cfg_to_icu_rules(rules, 'transliteration')
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Container class collecting all components required to transform an OSM name
from typing import Mapping, Optional, TYPE_CHECKING
from icu import Transliterator
-from nominatim.tokenizer.token_analysis.base import Analyzer
+from .token_analysis.base import Analyzer
if TYPE_CHECKING:
from typing import Any
- from nominatim.tokenizer.icu_rule_loader import TokenAnalyzerRule # pylint: disable=cyclic-import
+ from .icu_rule_loader import TokenAnalyzerRule # pylint: disable=cyclic-import
class ICUTokenAnalysis:
""" Container class collecting the transliterators and token analysis
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tokenizer implementing normalisation as used before Nominatim 4 but using
from pathlib import Path
from textwrap import dedent
-from nominatim.db.connection import connect, Connection, Cursor
-from nominatim.config import Configuration
-from nominatim.db.utils import CopyBuffer
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.data.place_info import PlaceInfo
-from nominatim.tokenizer.icu_rule_loader import ICURuleLoader
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_name import PlaceName
-from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis
-from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer
+from nominatim_core.db.connection import connect, Connection, Cursor
+from nominatim_core.config import Configuration
+from nominatim_core.db.utils import CopyBuffer
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from ..data.place_info import PlaceInfo
+from ..data.place_name import PlaceName
+from .icu_rule_loader import ICURuleLoader
+from .place_sanitizer import PlaceSanitizer
+from .icu_token_analysis import ICUTokenAnalysis
+from .base import AbstractAnalyzer, AbstractTokenizer
DBCFG_TERM_NORMALIZATION = "tokenizer_term_normalization"
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tokenizer implementing normalisation as used before Nominatim 4.
import psycopg2
import psycopg2.extras
-from nominatim.db.connection import connect, Connection
-from nominatim.config import Configuration
-from nominatim.db import properties
-from nominatim.db import utils as db_utils
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.data.place_info import PlaceInfo
-from nominatim.errors import UsageError
-from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer
+from nominatim_core.errors import UsageError
+from nominatim_core.db.connection import connect, Connection
+from nominatim_core.config import Configuration
+from nominatim_core.db import properties
+from nominatim_core.db import utils as db_utils
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from ..data.place_info import PlaceInfo
+from .base import AbstractAnalyzer, AbstractTokenizer
DBCFG_NORMALIZATION = "tokenizer_normalization"
DBCFG_MAXWORDFREQ = "tokenizer_maxwordfreq"
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Handler for cleaning name and address tags in place information before it
"""
from typing import Optional, List, Mapping, Sequence, Callable, Any, Tuple
-from nominatim.errors import UsageError
-from nominatim.config import Configuration
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
-from nominatim.tokenizer.sanitizers.base import SanitizerHandler, ProcessInfo
-from nominatim.data.place_name import PlaceName
-from nominatim.data.place_info import PlaceInfo
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from .sanitizers.config import SanitizerConfig
+from .sanitizers.base import SanitizerHandler, ProcessInfo
+from ..data.place_name import PlaceName
+from ..data.place_info import PlaceInfo
class PlaceSanitizer:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Common data types and protocols for sanitizers.
"""
from typing import Optional, List, Mapping, Callable
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
-from nominatim.data.place_info import PlaceInfo
-from nominatim.data.place_name import PlaceName
-from nominatim.typing import Protocol, Final
+from nominatim_core.typing import Protocol, Final
+from ...data.place_info import PlaceInfo
+from ...data.place_name import PlaceName
+from .config import SanitizerConfig
class ProcessInfo:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Sanitizer that preprocesses address tags for house numbers. The sanitizer
"""
from typing import Callable, Iterator, List
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.data.place_name import PlaceName
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from ...data.place_name import PlaceName
+from .base import ProcessInfo
+from .config import SanitizerConfig
class _HousenumberSanitizer:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Sanitizer that filters postcodes by their officially allowed pattern.
"""
from typing import Callable, Optional, Tuple
-from nominatim.data.postcode_format import PostcodeFormatter
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from ...data.postcode_format import PostcodeFormatter
+from .base import ProcessInfo
+from .config import SanitizerConfig
class _PostcodeSanitizer:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Sanitizer that preprocesses tags from the TIGER import.
from typing import Callable
import re
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from .base import ProcessInfo
+from .config import SanitizerConfig
COUNTY_MATCH = re.compile('(.*), [A-Z][A-Z]')
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Configuration for Sanitizers.
from collections import UserDict
import re
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
# working around missing generics in Python < 3.8
# See https://github.com/python/typing/issues/60#issuecomment-869757075
-# SPDX-License-Identifier: GPL-2.0-only\r
+# SPDX-License-Identifier: GPL-3.0-or-later\r
#\r
# This file is part of Nominatim. (https://nominatim.org)\r
#\r
-# Copyright (C) 2023 by the Nominatim developer community.\r
+# Copyright (C) 2024 by the Nominatim developer community.\r
# For a full list of authors see the git log.\r
"""\r
Sanitizer which prevents certain tags from getting into the search index.\r
"""\r
from typing import Callable, List, Tuple, Sequence\r
\r
-from nominatim.tokenizer.sanitizers.base import ProcessInfo\r
-from nominatim.data.place_name import PlaceName\r
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig\r
+from ...data.place_name import PlaceName\r
+from .base import ProcessInfo\r
+from .config import SanitizerConfig\r
\r
class _TagSanitizer:\r
\r
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Sanitizer that splits lists of names into their components.
"""
from typing import Callable
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from .base import ProcessInfo
+from .config import SanitizerConfig
def create(config: SanitizerConfig) -> Callable[[ProcessInfo], None]:
""" Create a name processing function that splits name values with
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
This sanitizer creates additional name variants for names that have
"""
from typing import Callable
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from .base import ProcessInfo
+from .config import SanitizerConfig
def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
This sanitizer sets the `analyzer` property depending on the
"""
from typing import Callable, Dict, Optional, List
-from nominatim.data import country_info
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from ...data import country_info
+from .base import ProcessInfo
+from .config import SanitizerConfig
class _AnalyzerByLanguage:
""" Processor for tagging the language of names in a place.
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
This sanitizer maps OSM data to Japanese block addresses.
from typing import Callable
from typing import List, Optional
-from nominatim.tokenizer.sanitizers.base import ProcessInfo
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
-from nominatim.data.place_name import PlaceName
+from .base import ProcessInfo
+from .config import SanitizerConfig
+from ...data.place_name import PlaceName
def create(_: SanitizerConfig) -> Callable[[ProcessInfo], None]:
"""Set up the sanitizer
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Common data types and protocols for analysers.
"""
from typing import Mapping, List, Any
-from nominatim.typing import Protocol
-from nominatim.data.place_name import PlaceName
+from nominatim_core.typing import Protocol
+from ...data.place_name import PlaceName
class Analyzer(Protocol):
""" The `create()` function of an analysis module needs to return an
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Parser for configuration for variants.
import itertools
import re
-from nominatim.config import flatten_config_list
-from nominatim.errors import UsageError
+from nominatim_core.config import flatten_config_list
+from nominatim_core.errors import UsageError
class ICUVariant(NamedTuple):
""" A single replacement rule for variant creation.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Generic processor for names that creates abbreviation variants.
import datrie
-from nominatim.errors import UsageError
-from nominatim.data.place_name import PlaceName
-from nominatim.tokenizer.token_analysis.config_variants import get_variant_config
-from nominatim.tokenizer.token_analysis.generic_mutation import MutationVariantGenerator
+from nominatim_core.errors import UsageError
+from ...data.place_name import PlaceName
+from .config_variants import get_variant_config
+from .generic_mutation import MutationVariantGenerator
### Configuration section
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Creator for mutation variants for the generic token analysis.
import logging
import re
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Specialized processor for housenumbers. Analyses common housenumber patterns
from typing import Any, List, cast
import re
-from nominatim.data.place_name import PlaceName
-from nominatim.tokenizer.token_analysis.generic_mutation import MutationVariantGenerator
+from ...data.place_name import PlaceName
+from .generic_mutation import MutationVariantGenerator
RE_NON_DIGIT = re.compile('[^0-9]')
RE_DIGIT_ALPHA = re.compile(r'(\d)\s*([^\d\s␣])')
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
"""
from typing import Any, List
-from nominatim.tokenizer.token_analysis.generic_mutation import MutationVariantGenerator
-from nominatim.data.place_name import PlaceName
+from ...data.place_name import PlaceName
+from .generic_mutation import MutationVariantGenerator
### Configuration section
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module with functions for importing, updating Nominatim databases
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Function to add additional OSM data from a file or the API into the database.
import logging
import urllib
-from nominatim.db.connection import connect
-from nominatim.tools.exec_utils import run_osm2pgsql, get_url
+from nominatim_core.db.connection import connect
+from nominatim_core.utils.url_utils import get_url
+from .exec_utils import run_osm2pgsql
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for database analysis and maintenance.
from psycopg2.extras import Json, register_hstore
from psycopg2 import DataError
-from nominatim.config import Configuration
-from nominatim.db.connection import connect, Cursor
-from nominatim.tokenizer import factory as tokenizer_factory
-from nominatim.errors import UsageError
-from nominatim.data.place_info import PlaceInfo
-from nominatim.typing import DictCursorResult
+from nominatim_core.typing import DictCursorResult
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect, Cursor
+from nominatim_core.errors import UsageError
+from ..tokenizer import factory as tokenizer_factory
+from ..data.place_info import PlaceInfo
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Collection of functions that check if the database is complete and functional.
from enum import Enum
from textwrap import dedent
-from nominatim.config import Configuration
-from nominatim.db.connection import connect, Connection
-from nominatim.db import properties
-from nominatim.errors import UsageError
-from nominatim.tokenizer import factory as tokenizer_factory
-from nominatim.tools import freeze
-from nominatim.version import NOMINATIM_VERSION, parse_version
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect, Connection
+from nominatim_core.db import properties
+from nominatim_core.errors import UsageError
+from ..tokenizer import factory as tokenizer_factory
+from . import freeze
+from ..version import NOMINATIM_VERSION, parse_version
CHECKLIST = []
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Collection of host system information including software versions, memory,
import psutil
from psycopg2.extensions import make_dsn, parse_dsn
-from nominatim.config import Configuration
-from nominatim.db.connection import connect
-from nominatim.version import NOMINATIM_VERSION
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect
+from ..version import NOMINATIM_VERSION
def convert_version(ver_tup: Tuple[int, int]) -> str:
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Exporting a Nominatim database to SQlite.
import sqlalchemy as sa
-from nominatim.typing import SaSelect, SaRow
-from nominatim.db.sqlalchemy_types import Geometry, IntArray
-from nominatim.api.search.query_analyzer_factory import make_query_analyzer
-import nominatim.api as napi
+import nominatim_api as napi
+from nominatim_api.search.query_analyzer_factory import make_query_analyzer
+from nominatim_core.typing import SaSelect, SaRow
+from nominatim_core.db.sqlalchemy_types import Geometry, IntArray
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for setting up and importing a new Nominatim database.
import psutil
from psycopg2 import sql as pysql
-from nominatim.config import Configuration
-from nominatim.db.connection import connect, get_pg_env, Connection
-from nominatim.db.async_connection import DBConnection
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.tools.exec_utils import run_osm2pgsql
-from nominatim.errors import UsageError
-from nominatim.version import POSTGRESQL_REQUIRED_VERSION, \
- POSTGIS_REQUIRED_VERSION
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect, get_pg_env, Connection
+from nominatim_core.db.async_connection import DBConnection
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from .exec_utils import run_osm2pgsql
+from ..version import POSTGRESQL_REQUIRED_VERSION, POSTGIS_REQUIRED_VERSION
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper functions for executing external programs.
"""
-from typing import Any, Mapping, IO
+from typing import Any, Mapping
import logging
import os
import subprocess
import shutil
-import urllib.request as urlrequest
-from nominatim.typing import StrPath
-from nominatim.version import NOMINATIM_VERSION
-from nominatim.db.connection import get_pg_env
+from nominatim_core.typing import StrPath
+from nominatim_core.db.connection import get_pg_env
LOG = logging.getLogger()
subprocess.run(cmd, cwd=options.get('cwd', '.'),
input=options.get('import_data'),
env=env, check=True)
-
-
-def get_url(url: str) -> str:
- """ Get the contents from the given URL and return it as a UTF-8 string.
- """
- headers = {"User-Agent": f"Nominatim/{NOMINATIM_VERSION!s}"}
-
- try:
- request = urlrequest.Request(url, headers=headers)
- with urlrequest.urlopen(request) as response: # type: IO[bytes]
- return response.read().decode('utf-8')
- except Exception:
- LOG.fatal('Failed to load URL: %s', url)
- raise
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for removing unnecessary data from the database.
from psycopg2 import sql as pysql
-from nominatim.db.connection import Connection
+from nominatim_core.db.connection import Connection
UPDATE_TABLES = [
'address_levels',
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for database migration to newer software versions.
from psycopg2 import sql as pysql
-from nominatim.config import Configuration
-from nominatim.db import properties
-from nominatim.db.connection import connect, Connection
-from nominatim.version import NominatimVersion, NOMINATIM_VERSION, parse_version
-from nominatim.tools import refresh
-from nominatim.tokenizer import factory as tokenizer_factory
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
+from nominatim_core.config import Configuration
+from nominatim_core.db import properties
+from nominatim_core.db.connection import connect, Connection
+from ..version import NominatimVersion, NOMINATIM_VERSION, parse_version
+from ..tokenizer import factory as tokenizer_factory
+from . import refresh
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for importing, updating and otherwise maintaining the table
from psycopg2 import sql as pysql
-from nominatim.db.connection import connect, Connection
-from nominatim.utils.centroid import PointsCentroid
-from nominatim.data.postcode_format import PostcodeFormatter, CountryPostcodeMatcher
-from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer
+from nominatim_core.db.connection import connect, Connection
+from nominatim_core.utils.centroid import PointsCentroid
+from ..data.postcode_format import PostcodeFormatter, CountryPostcodeMatcher
+from ..tokenizer.base import AbstractAnalyzer, AbstractTokenizer
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for bringing auxiliary data in the database up-to-date.
from psycopg2 import sql as pysql
-from nominatim.config import Configuration
-from nominatim.db.connection import Connection, connect
-from nominatim.db.utils import execute_file, CopyBuffer
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.version import NOMINATIM_VERSION
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import Connection, connect
+from nominatim_core.db.utils import execute_file, CopyBuffer
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from ..version import NOMINATIM_VERSION
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for updating a database from a replication source.
import urllib.request as urlrequest
import requests
-from nominatim.db import status
-from nominatim.db.connection import Connection, connect
-from nominatim.tools.exec_utils import run_osm2pgsql
-from nominatim.errors import UsageError
+
+from nominatim_core.errors import UsageError
+from nominatim_core.db import status
+from nominatim_core.db.connection import Connection, connect
+from .exec_utils import run_osm2pgsql
try:
from osmium.replication.server import ReplicationServer
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Contains the class which handles statistics for the
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module containing the SPCsvLoader class.
from typing import Iterable
import csv
import os
-from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
-from nominatim.errors import UsageError
+
+from nominatim_core.errors import UsageError
+from .special_phrase import SpecialPhrase
class SPCsvLoader:
"""
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module containing the class handling the import
from psycopg2.sql import Identifier, SQL
-from nominatim.config import Configuration
-from nominatim.db.connection import Connection
-from nominatim.tools.special_phrases.importer_statistics import SpecialPhrasesImporterStatistics
-from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
-from nominatim.tokenizer.base import AbstractTokenizer
-from nominatim.typing import Protocol
+from nominatim_core.typing import Protocol
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import Connection
+from .importer_statistics import SpecialPhrasesImporterStatistics
+from .special_phrase import SpecialPhrase
+from ...tokenizer.base import AbstractTokenizer
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module containing the SPWikiLoader class.
import re
import logging
-from nominatim.config import Configuration
-from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
-from nominatim.tools.exec_utils import get_url
+from nominatim_core.config import Configuration
+from nominatim_core.utils.url_utils import get_url
+from .special_phrase import SpecialPhrase
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Module containing the class SpecialPhrase.
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Functions for importing tiger data and handling tarbar and directory files
from psycopg2.extras import Json
-from nominatim.config import Configuration
-from nominatim.db.connection import connect
-from nominatim.db.async_connection import WorkerPool
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.errors import UsageError
-from nominatim.data.place_info import PlaceInfo
-from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer
-from nominatim.tools import freeze
+from nominatim_core.config import Configuration
+from nominatim_core.db.connection import connect
+from nominatim_core.db.async_connection import WorkerPool
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from nominatim_core.errors import UsageError
+from ..data.place_info import PlaceInfo
+from ..tokenizer.base import AbstractAnalyzer, AbstractTokenizer
+from . import freeze
LOG = logging.getLogger()
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Version information for Nominatim.