split code into submodules

This commit is contained in:
Sarah Hoffmann 2024-05-16 11:55:17 +02:00
parent 0fb4fe8e4d
commit 6e89310a92
137 changed files with 757 additions and 716 deletions

View File

@ -1,4 +0,0 @@
if __name__ == '__main__':
from nominatim import cli
exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))

View File

@ -1,28 +0,0 @@
# 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

View File

@ -1,15 +0,0 @@
# 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()

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
The public interface of the Nominatim library. The public interface of the Nominatim library.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Extended SQLAlchemy connection class that also includes access to the schema. Extended SQLAlchemy connection class that also includes access to the schema.
@ -14,16 +14,16 @@ import asyncio
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.ext.asyncio import AsyncConnection from sqlalchemy.ext.asyncio import AsyncConnection
from nominatim.typing import SaFromClause from nominatim_core.typing import SaFromClause
from nominatim.db.sqlalchemy_schema import SearchTables from nominatim_core.db.sqlalchemy_schema import SearchTables
from nominatim.db.sqlalchemy_types import Geometry from nominatim_core.db.sqlalchemy_types import Geometry
from nominatim.api.logging import log from .logging import log
T = TypeVar('T') T = TypeVar('T')
class SearchConnection: class SearchConnection:
""" An extended SQLAlchemy connection class, that also contains """ 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. connection can be accessed with the 'connection' property.
The 't' property is the collection of Nominatim tables. The 't' property is the collection of Nominatim tables.
""" """

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of classes for API access via libraries. Implementation of classes for API access via libraries.
@ -16,18 +16,18 @@ from pathlib import Path
import sqlalchemy as sa import sqlalchemy as sa
import sqlalchemy.ext.asyncio as sa_asyncio import sqlalchemy.ext.asyncio as sa_asyncio
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.db.sqlalchemy_schema import SearchTables from nominatim_core.db.sqlalchemy_schema import SearchTables
from nominatim.db.async_core_library import PGCORE_LIB, PGCORE_ERROR from nominatim_core.db.async_core_library import PGCORE_LIB, PGCORE_ERROR
import nominatim.db.sqlite_functions from nominatim_core.config import Configuration
from nominatim.config import Configuration from .sql import sqlite_functions, sqlalchemy_functions #pylint: disable=unused-import
from nominatim.api.connection import SearchConnection from .connection import SearchConnection
from nominatim.api.status import get_status, StatusResult from .status import get_status, StatusResult
from nominatim.api.lookup import get_detailed_place, get_simple_place from .lookup import get_detailed_place, get_simple_place
from nominatim.api.reverse import ReverseGeocoder from .reverse import ReverseGeocoder
from nominatim.api.search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer from .search import ForwardGeocoder, Phrase, PhraseType, make_query_analyzer
import nominatim.api.types as ntyp from . import types as ntyp
from nominatim.api.results import DetailedResult, ReverseResult, SearchResults from .results import DetailedResult, ReverseResult, SearchResults
class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
@ -127,7 +127,7 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
@sa.event.listens_for(engine.sync_engine, "connect") @sa.event.listens_for(engine.sync_engine, "connect")
def _on_sqlite_connect(dbapi_con: Any, _: Any) -> None: def _on_sqlite_connect(dbapi_con: Any, _: Any) -> None:
dbapi_con.run_async(lambda conn: conn.enable_load_extension(True)) 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 = dbapi_con.cursor()
cursor.execute("SELECT load_extension('mod_spatialite')") cursor.execute("SELECT load_extension('mod_spatialite')")
cursor.execute('SELECT SetDecimalPrecision(7)') cursor.execute('SELECT SetDecimalPrecision(7)')

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper functions for localizing names of results. Helper functions for localizing names of results.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Functions for specialised logging with HTML output. Functions for specialised logging with HTML output.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of place lookup by ID. Implementation of place lookup by ID.
@ -12,18 +12,17 @@ import datetime as dt
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaColumn, SaRow, SaSelect from nominatim_core.typing import SaColumn, SaRow, SaSelect
from nominatim.api.connection import SearchConnection from .connection import SearchConnection
import nominatim.api.types as ntyp from .logging import log
import nominatim.api.results as nres from . import types as ntyp
from nominatim.api.logging import log from . import results as nres
RowFunc = Callable[[Optional[SaRow], Type[nres.BaseResultT]], Optional[nres.BaseResultT]] RowFunc = Callable[[Optional[SaRow], Type[nres.BaseResultT]], Optional[nres.BaseResultT]]
GeomFunc = Callable[[SaSelect, SaColumn], SaSelect] GeomFunc = Callable[[SaSelect, SaColumn], SaSelect]
async def find_in_placex(conn: SearchConnection, place: ntyp.PlaceRef, async def find_in_placex(conn: SearchConnection, place: ntyp.PlaceRef,
add_geometries: GeomFunc) -> Optional[SaRow]: add_geometries: GeomFunc) -> Optional[SaRow]:
""" Search for the given place in the placex table and return the """ Search for the given place in the placex table and return the

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper classes and functions for formatting results into API responses. Helper classes and functions for formatting results into API responses.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Dataclasses for search results and helper functions to fill them. Dataclasses for search results and helper functions to fill them.
@ -18,12 +18,12 @@ import datetime as dt
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaSelect, SaRow from nominatim_core.typing import SaSelect, SaRow
from nominatim.db.sqlalchemy_types import Geometry from nominatim_core.db.sqlalchemy_types import Geometry
from nominatim.api.types import Point, Bbox, LookupDetails from .types import Point, Bbox, LookupDetails
from nominatim.api.connection import SearchConnection from .connection import SearchConnection
from nominatim.api.logging import log from .logging import log
from nominatim.api.localization import Locales from .localization import Locales
# This file defines complex result data classes. # This file defines complex result data classes.
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of reverse geocoding. Implementation of reverse geocoding.
@ -12,13 +12,13 @@ import functools
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow,\ from nominatim_core.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow,\
SaBind, SaLambdaSelect SaBind, SaLambdaSelect
from nominatim.api.connection import SearchConnection from nominatim_core.db.sqlalchemy_types import Geometry
import nominatim.api.results as nres from .connection import SearchConnection
from nominatim.api.logging import log from . import results as nres
from nominatim.api.types import AnyPoint, DataLayer, ReverseDetails, GeometryFormat, Bbox from .logging import log
from nominatim.db.sqlalchemy_types import Geometry from .types import AnyPoint, DataLayer, ReverseDetails, GeometryFormat, Bbox
# In SQLAlchemy expression which compare with NULL need to be expressed with # In SQLAlchemy expression which compare with NULL need to be expressed with
# the equal sign. # the equal sign.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Module for forward search. Module for forward search.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Conversion from token assignment to an abstract DB search. Conversion from token assignment to an abstract DB search.
@ -10,12 +10,12 @@ Conversion from token assignment to an abstract DB search.
from typing import Optional, List, Tuple, Iterator, Dict from typing import Optional, List, Tuple, Iterator, Dict
import heapq import heapq
from nominatim.api.types import SearchDetails, DataLayer from ..types import SearchDetails, DataLayer
from nominatim.api.search.query import QueryStruct, Token, TokenType, TokenRange, BreakType from .query import QueryStruct, Token, TokenType, TokenRange, BreakType
from nominatim.api.search.token_assignment import TokenAssignment from .token_assignment import TokenAssignment
import nominatim.api.search.db_search_fields as dbf from . import db_search_fields as dbf
import nominatim.api.search.db_searches as dbs from . import db_searches as dbs
import nominatim.api.search.db_search_lookups as lookups from . import db_search_lookups as lookups
def wrap_near_search(categories: List[Tuple[str, str]], def wrap_near_search(categories: List[Tuple[str, str]],

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Data structures for more complex fields in abstract search descriptions. Data structures for more complex fields in abstract search descriptions.
@ -12,10 +12,10 @@ import dataclasses
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaFromClause, SaColumn, SaExpression from nominatim_core.typing import SaFromClause, SaColumn, SaExpression
from nominatim.api.search.query import Token from .query import Token
import nominatim.api.search.db_search_lookups as lookups from . import db_search_lookups as lookups
from nominatim.utils.json_writer import JsonWriter from nominatim_core.utils.json_writer import JsonWriter
@dataclasses.dataclass @dataclasses.dataclass

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of lookup functions for the search_name table. Implementation of lookup functions for the search_name table.
@ -12,8 +12,8 @@ from typing import List, Any
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles from sqlalchemy.ext.compiler import compiles
from nominatim.typing import SaFromClause from nominatim_core.typing import SaFromClause
from nominatim.db.sqlalchemy_types import IntArray from nominatim_core.db.sqlalchemy_types import IntArray
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the actual database accesses for forward search. Implementation of the actual database accesses for forward search.
@ -12,13 +12,13 @@ import abc
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaFromClause, SaScalarSelect, SaColumn, \ from nominatim_core.typing import SaFromClause, SaScalarSelect, SaColumn, \
SaExpression, SaSelect, SaLambdaSelect, SaRow, SaBind SaExpression, SaSelect, SaLambdaSelect, SaRow, SaBind
from nominatim.api.connection import SearchConnection from nominatim_core.db.sqlalchemy_types import Geometry, IntArray
from nominatim.api.types import SearchDetails, DataLayer, GeometryFormat, Bbox from ..connection import SearchConnection
import nominatim.api.results as nres from ..types import SearchDetails, DataLayer, GeometryFormat, Bbox
from nominatim.api.search.db_search_fields import SearchData, WeightedCategories from .. import results as nres
from nominatim.db.sqlalchemy_types import Geometry, IntArray from .db_search_fields import SearchData, WeightedCategories
#pylint: disable=singleton-comparison,not-callable #pylint: disable=singleton-comparison,not-callable
#pylint: disable=too-many-branches,too-many-arguments,too-many-locals,too-many-statements #pylint: disable=too-many-branches,too-many-arguments,too-many-locals,too-many-statements

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Public interface to the search code. Public interface to the search code.
@ -13,15 +13,15 @@ import re
import datetime as dt import datetime as dt
import difflib import difflib
from nominatim.api.connection import SearchConnection from ..connection import SearchConnection
from nominatim.api.types import SearchDetails from ..types import SearchDetails
from nominatim.api.results import SearchResult, SearchResults, add_result_details from ..results import SearchResult, SearchResults, add_result_details
from nominatim.api.search.token_assignment import yield_token_assignments from ..logging import log
from nominatim.api.search.db_search_builder import SearchBuilder, build_poi_search, wrap_near_search from .token_assignment import yield_token_assignments
from nominatim.api.search.db_searches import AbstractSearch from .db_search_builder import SearchBuilder, build_poi_search, wrap_near_search
from nominatim.api.search.query_analyzer_factory import make_query_analyzer, AbstractQueryAnalyzer from .db_searches import AbstractSearch
from nominatim.api.search.query import Phrase, QueryStruct from .query_analyzer_factory import make_query_analyzer, AbstractQueryAnalyzer
from nominatim.api.logging import log from .query import Phrase, QueryStruct
class ForwardGeocoder: class ForwardGeocoder:
""" Main class responsible for place search. """ Main class responsible for place search.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of query analysis for the ICU tokenizer. Implementation of query analysis for the ICU tokenizer.
@ -16,12 +16,12 @@ from icu import Transliterator
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaRow from nominatim_core.typing import SaRow
from nominatim.api.connection import SearchConnection from nominatim_core.db.sqlalchemy_types import Json
from nominatim.api.logging import log from ..connection import SearchConnection
from nominatim.api.search import query as qmod from ..logging import log
from nominatim.api.search.query_analyzer_factory import AbstractQueryAnalyzer from ..search import query as qmod
from nominatim.db.sqlalchemy_types import Json from ..search.query_analyzer_factory import AbstractQueryAnalyzer
DB_TO_TOKEN_TYPE = { DB_TO_TOKEN_TYPE = {

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of query analysis for the legacy tokenizer. Implementation of query analysis for the legacy tokenizer.
@ -14,11 +14,11 @@ import dataclasses
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.typing import SaRow from nominatim_core.typing import SaRow
from nominatim.api.connection import SearchConnection from ..connection import SearchConnection
from nominatim.api.logging import log from ..logging import log
from nominatim.api.search import query as qmod from . import query as qmod
from nominatim.api.search.query_analyzer_factory import AbstractQueryAnalyzer from .query_analyzer_factory import AbstractQueryAnalyzer
def yield_words(terms: List[str], start: int) -> Iterator[Tuple[str, qmod.TokenRange]]: def yield_words(terms: List[str], start: int) -> Iterator[Tuple[str, qmod.TokenRange]]:
""" Return all combinations of words in the terms list after the """ Return all combinations of words in the terms list after the

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Datastructures for a tokenized query. Datastructures for a tokenized query.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Factory for creating a query analyzer for the configured tokenizer. Factory for creating a query analyzer for the configured tokenizer.
@ -12,11 +12,11 @@ from abc import ABC, abstractmethod
from pathlib import Path from pathlib import Path
import importlib import importlib
from nominatim.api.logging import log from ..logging import log
from nominatim.api.connection import SearchConnection from ..connection import SearchConnection
if TYPE_CHECKING: if TYPE_CHECKING:
from nominatim.api.search.query import Phrase, QueryStruct from .query import Phrase, QueryStruct
class AbstractQueryAnalyzer(ABC): class AbstractQueryAnalyzer(ABC):
""" Class for analysing incoming queries. """ Class for analysing incoming queries.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Create query interpretations where each vertice in the query is assigned Create query interpretations where each vertice in the query is assigned
@ -11,8 +11,8 @@ a specific function (expressed as a token type).
from typing import Optional, List, Iterator from typing import Optional, List, Iterator
import dataclasses import dataclasses
import nominatim.api.search.query as qmod from ..logging import log
from nominatim.api.logging import log from . import query as qmod
# pylint: disable=too-many-return-statements,too-many-branches # pylint: disable=too-many-return-statements,too-many-branches

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Server implementation using the falcon webserver framework. Server implementation using the falcon webserver framework.
@ -14,10 +14,10 @@ import asyncio
from falcon.asgi import App, Request, Response from falcon.asgi import App, Request, Response
from nominatim.api import NominatimAPIAsync from nominatim_core.config import Configuration
import nominatim.api.v1 as api_impl from ...core import NominatimAPIAsync
import nominatim.api.logging as loglib from ... import v1 as api_impl
from nominatim.config import Configuration from ... import logging as loglib
class HTTPNominatimError(Exception): class HTTPNominatimError(Exception):
""" A special exception class for errors raised during processing. """ A special exception class for errors raised during processing.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Server implementation using the starlette webserver framework. Server implementation using the starlette webserver framework.
@ -21,10 +21,10 @@ from starlette.middleware import Middleware
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.middleware.cors import CORSMiddleware from starlette.middleware.cors import CORSMiddleware
from nominatim.api import NominatimAPIAsync from nominatim_core.config import Configuration
import nominatim.api.v1 as api_impl from ...core import NominatimAPIAsync
import nominatim.api.logging as loglib from ... import v1 as api_impl
from nominatim.config import Configuration from ... import logging as loglib
class ParamWrapper(api_impl.ASGIAdaptor): class ParamWrapper(api_impl.ASGIAdaptor):
""" Adaptor class for server glue to Starlette framework. """ Adaptor class for server glue to Starlette framework.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Custom functions and expressions for SQLAlchemy. Custom functions and expressions for SQLAlchemy.
@ -13,7 +13,7 @@ from typing import Any
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles from sqlalchemy.ext.compiler import compiles
from nominatim.typing import SaColumn from nominatim_core.typing import SaColumn
# pylint: disable=all # pylint: disable=all

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Custom functions for SQLite. Custom functions for SQLite.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Classes and function related to status call. Classes and function related to status call.
@ -13,8 +13,8 @@ import dataclasses
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.api.connection import SearchConnection from .connection import SearchConnection
from nominatim import version from .version import NOMINATIM_API_VERSION
@dataclasses.dataclass @dataclasses.dataclass
class StatusResult: class StatusResult:
@ -22,9 +22,9 @@ class StatusResult:
""" """
status: int status: int
message: str message: str
software_version = version.NOMINATIM_VERSION software_version = NOMINATIM_API_VERSION
data_updated: Optional[dt.datetime] = None data_updated: Optional[dt.datetime] = None
database_version: Optional[version.NominatimVersion] = None database_version: Optional[str] = None
async def get_status(conn: SearchConnection) -> StatusResult: async def get_status(conn: SearchConnection) -> StatusResult:
@ -44,8 +44,7 @@ async def get_status(conn: SearchConnection) -> StatusResult:
# Database version # Database version
try: try:
verstr = await conn.get_property('database_version') status.database_version = await conn.get_property('database_version')
status.database_version = version.parse_version(verstr)
except ValueError: except ValueError:
pass pass

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Complex datatypes used by the Nominatim API. Complex datatypes used by the Nominatim API.
@ -16,8 +16,8 @@ import math
from struct import unpack from struct import unpack
from binascii import unhexlify from binascii import unhexlify
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.api.localization import Locales from .localization import Locales
# pylint: disable=no-member,too-many-boolean-expressions,too-many-instance-attributes # pylint: disable=no-member,too-many-boolean-expressions,too-many-instance-attributes

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of API version v1 (aka the legacy version). Implementation of API version v1 (aka the legacy version).
@ -10,11 +10,11 @@ Implementation of API version v1 (aka the legacy version).
#pylint: disable=useless-import-alias #pylint: disable=useless-import-alias
from nominatim.api.v1.server_glue import (ASGIAdaptor as ASGIAdaptor, from .server_glue import (ASGIAdaptor as ASGIAdaptor,
EndpointFunc as EndpointFunc, EndpointFunc as EndpointFunc,
ROUTES as ROUTES) ROUTES as ROUTES)
import nominatim.api.v1.format as _format from . import format as _format
list_formats = _format.dispatch.list_formats list_formats = _format.dispatch.list_formats
supports_format = _format.dispatch.supports_format supports_format = _format.dispatch.supports_format

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Hard-coded information about tag categories. Hard-coded information about tag categories.
@ -12,7 +12,8 @@ version a more flexible formatting is required.
""" """
from typing import Tuple, Optional, Mapping, Union 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]], def get_label_tag(category: Tuple[str, str], extratags: Optional[Mapping[str, str]],
rank: int, country: Optional[str]) -> str: rank: int, country: Optional[str]) -> str:
@ -41,7 +42,7 @@ def get_label_tag(category: Tuple[str, str], extratags: Optional[Mapping[str, st
return label.lower().replace(' ', '_') 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 """ Compute a bounding box for the result. For ways and relations
a given boundingbox is used. For all other object, a box is computed a given boundingbox is used. For all other object, a box is computed
around the centroid according to dimensions derived from the around the centroid according to dimensions derived from the
@ -49,7 +50,7 @@ def bbox_from_result(result: Union[napi.ReverseResult, napi.SearchResult]) -> na
""" """
if (result.osm_object and result.osm_object[0] == 'N') or result.bbox is None: if (result.osm_object and result.osm_object[0] == 'N') or result.bbox is None:
extent = NODE_EXTENT.get(result.category, 0.00005) 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 return result.bbox

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Output formatters for API version v1. Output formatters for API version v1.
@ -11,11 +11,14 @@ from typing import List, Dict, Mapping, Any
import collections import collections
import datetime as dt import datetime as dt
import nominatim.api as napi from nominatim_core.utils.json_writer import JsonWriter
from nominatim.api.result_formatting import FormatDispatcher from ..status import StatusResult
from nominatim.api.v1.classtypes import ICONS from ..results import DetailedResult, ReverseResults, SearchResults, \
from nominatim.api.v1 import format_json, format_xml AddressLines, AddressLine
from nominatim.utils.json_writer import JsonWriter 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]]): class RawDataList(List[Dict[str, Any]]):
""" Data type for formatting raw data lists 'as is' in json. """ Data type for formatting raw data lists 'as is' in json.
@ -23,16 +26,16 @@ class RawDataList(List[Dict[str, Any]]):
dispatch = FormatDispatcher() dispatch = FormatDispatcher()
@dispatch.format_func(napi.StatusResult, 'text') @dispatch.format_func(StatusResult, 'text')
def _format_status_text(result: napi.StatusResult, _: Mapping[str, Any]) -> str: def _format_status_text(result: StatusResult, _: Mapping[str, Any]) -> str:
if result.status: if result.status:
return f"ERROR: {result.message}" return f"ERROR: {result.message}"
return 'OK' return 'OK'
@dispatch.format_func(napi.StatusResult, 'json') @dispatch.format_func(StatusResult, 'json')
def _format_status_json(result: napi.StatusResult, _: Mapping[str, Any]) -> str: def _format_status_json(result: StatusResult, _: Mapping[str, Any]) -> str:
out = JsonWriter() out = JsonWriter()
out.start_object()\ out.start_object()\
@ -47,8 +50,8 @@ def _format_status_json(result: napi.StatusResult, _: Mapping[str, Any]) -> str:
return out() return out()
def _add_address_row(writer: JsonWriter, row: napi.AddressLine, def _add_address_row(writer: JsonWriter, row: AddressLine,
locales: napi.Locales) -> None: locales: Locales) -> None:
writer.start_object()\ writer.start_object()\
.keyval('localname', locales.display_name(row.names))\ .keyval('localname', locales.display_name(row.names))\
.keyval_not_none('place_id', row.place_id) .keyval_not_none('place_id', row.place_id)
@ -69,8 +72,8 @@ def _add_address_row(writer: JsonWriter, row: napi.AddressLine,
.end_object() .end_object()
def _add_address_rows(writer: JsonWriter, section: str, rows: napi.AddressLines, def _add_address_rows(writer: JsonWriter, section: str, rows: AddressLines,
locales: napi.Locales) -> None: locales: Locales) -> None:
writer.key(section).start_array() writer.key(section).start_array()
for row in rows: for row in rows:
_add_address_row(writer, row, locales) _add_address_row(writer, row, locales)
@ -78,8 +81,8 @@ def _add_address_rows(writer: JsonWriter, section: str, rows: napi.AddressLines,
writer.end_array().next() writer.end_array().next()
def _add_parent_rows_grouped(writer: JsonWriter, rows: napi.AddressLines, def _add_parent_rows_grouped(writer: JsonWriter, rows: AddressLines,
locales: napi.Locales) -> None: locales: Locales) -> None:
# group by category type # group by category type
data = collections.defaultdict(list) data = collections.defaultdict(list)
for row in rows: for row in rows:
@ -98,9 +101,9 @@ def _add_parent_rows_grouped(writer: JsonWriter, rows: napi.AddressLines,
writer.end_object().next() writer.end_object().next()
@dispatch.format_func(napi.DetailedResult, 'json') @dispatch.format_func(DetailedResult, 'json')
def _format_details_json(result: napi.DetailedResult, options: Mapping[str, Any]) -> str: def _format_details_json(result: DetailedResult, options: Mapping[str, Any]) -> str:
locales = options.get('locales', napi.Locales()) locales = options.get('locales', Locales())
geom = result.geometry.get('geojson') geom = result.geometry.get('geojson')
centroid = result.centroid.to_geojson() centroid = result.centroid.to_geojson()
@ -169,41 +172,41 @@ def _format_details_json(result: napi.DetailedResult, options: Mapping[str, Any]
return out() return out()
@dispatch.format_func(napi.ReverseResults, 'xml') @dispatch.format_func(ReverseResults, 'xml')
def _format_reverse_xml(results: napi.ReverseResults, options: Mapping[str, Any]) -> str: def _format_reverse_xml(results: ReverseResults, options: Mapping[str, Any]) -> str:
return format_xml.format_base_xml(results, return format_xml.format_base_xml(results,
options, True, 'reversegeocode', options, True, 'reversegeocode',
{'querystring': options.get('query', '')}) {'querystring': options.get('query', '')})
@dispatch.format_func(napi.ReverseResults, 'geojson') @dispatch.format_func(ReverseResults, 'geojson')
def _format_reverse_geojson(results: napi.ReverseResults, def _format_reverse_geojson(results: ReverseResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_geojson(results, options, True) return format_json.format_base_geojson(results, options, True)
@dispatch.format_func(napi.ReverseResults, 'geocodejson') @dispatch.format_func(ReverseResults, 'geocodejson')
def _format_reverse_geocodejson(results: napi.ReverseResults, def _format_reverse_geocodejson(results: ReverseResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_geocodejson(results, options, True) return format_json.format_base_geocodejson(results, options, True)
@dispatch.format_func(napi.ReverseResults, 'json') @dispatch.format_func(ReverseResults, 'json')
def _format_reverse_json(results: napi.ReverseResults, def _format_reverse_json(results: ReverseResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, True, return format_json.format_base_json(results, options, True,
class_label='class') class_label='class')
@dispatch.format_func(napi.ReverseResults, 'jsonv2') @dispatch.format_func(ReverseResults, 'jsonv2')
def _format_reverse_jsonv2(results: napi.ReverseResults, def _format_reverse_jsonv2(results: ReverseResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, True, return format_json.format_base_json(results, options, True,
class_label='category') class_label='category')
@dispatch.format_func(napi.SearchResults, 'xml') @dispatch.format_func(SearchResults, 'xml')
def _format_search_xml(results: napi.SearchResults, options: Mapping[str, Any]) -> str: def _format_search_xml(results: SearchResults, options: Mapping[str, Any]) -> str:
extra = {'querystring': options.get('query', '')} extra = {'querystring': options.get('query', '')}
for attr in ('more_url', 'exclude_place_ids', 'viewbox'): for attr in ('more_url', 'exclude_place_ids', 'viewbox'):
if options.get(attr): if options.get(attr):
@ -213,27 +216,27 @@ def _format_search_xml(results: napi.SearchResults, options: Mapping[str, Any])
@dispatch.format_func(napi.SearchResults, 'geojson') @dispatch.format_func(SearchResults, 'geojson')
def _format_search_geojson(results: napi.SearchResults, def _format_search_geojson(results: SearchResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_geojson(results, options, False) return format_json.format_base_geojson(results, options, False)
@dispatch.format_func(napi.SearchResults, 'geocodejson') @dispatch.format_func(SearchResults, 'geocodejson')
def _format_search_geocodejson(results: napi.SearchResults, def _format_search_geocodejson(results: SearchResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_geocodejson(results, options, False) return format_json.format_base_geocodejson(results, options, False)
@dispatch.format_func(napi.SearchResults, 'json') @dispatch.format_func(SearchResults, 'json')
def _format_search_json(results: napi.SearchResults, def _format_search_json(results: SearchResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, False, return format_json.format_base_json(results, options, False,
class_label='class') class_label='class')
@dispatch.format_func(napi.SearchResults, 'jsonv2') @dispatch.format_func(SearchResults, 'jsonv2')
def _format_search_jsonv2(results: napi.SearchResults, def _format_search_jsonv2(results: SearchResults,
options: Mapping[str, Any]) -> str: options: Mapping[str, Any]) -> str:
return format_json.format_base_json(results, options, False, return format_json.format_base_json(results, options, False,
class_label='category') class_label='category')

View File

@ -2,16 +2,16 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper functions for output of results in json formats. Helper functions for output of results in json formats.
""" """
from typing import Mapping, Any, Optional, Tuple, Union from typing import Mapping, Any, Optional, Tuple, Union
import nominatim.api as napi from nominatim_core.utils.json_writer import JsonWriter
import nominatim.api.v1.classtypes as cl from ..results import AddressLines, ReverseResults, SearchResults
from nominatim.utils.json_writer import JsonWriter from . import classtypes as cl
#pylint: disable=too-many-branches #pylint: disable=too-many-branches
@ -21,7 +21,7 @@ def _write_osm_id(out: JsonWriter, osm_object: Optional[Tuple[str, int]]) -> Non
.keyval('osm_id', osm_object[1]) .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: country_code: Optional[str]) -> None:
parts = {} parts = {}
for line in (address or []): for line in (address or []):
@ -42,7 +42,7 @@ def _write_typed_address(out: JsonWriter, address: Optional[napi.AddressLines],
def _write_geocodejson_address(out: JsonWriter, def _write_geocodejson_address(out: JsonWriter,
address: Optional[napi.AddressLines], address: Optional[AddressLines],
obj_place_id: Optional[int], obj_place_id: Optional[int],
country_code: Optional[str]) -> None: country_code: Optional[str]) -> None:
extra = {} extra = {}
@ -66,7 +66,7 @@ def _write_geocodejson_address(out: JsonWriter,
out.keyval('country_code', country_code) 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, options: Mapping[str, Any], simple: bool,
class_label: str) -> str: class_label: str) -> str:
""" Return the result list as a simple json string in custom Nominatim format. """ Return the result list as a simple json string in custom Nominatim format.
@ -142,7 +142,7 @@ def format_base_json(results: Union[napi.ReverseResults, napi.SearchResults],
return out() return out()
def format_base_geojson(results: Union[napi.ReverseResults, napi.SearchResults], def format_base_geojson(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any], options: Mapping[str, Any],
simple: bool) -> str: simple: bool) -> str:
""" Return the result list as a geojson string. """ Return the result list as a geojson string.
@ -204,7 +204,7 @@ def format_base_geojson(results: Union[napi.ReverseResults, napi.SearchResults],
return out() 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: options: Mapping[str, Any], simple: bool) -> str:
""" Return the result list as a geocodejson string. """ Return the result list as a geocodejson string.
""" """

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper functions for output of results in XML format. Helper functions for output of results in XML format.
@ -11,12 +11,13 @@ from typing import Mapping, Any, Optional, Union
import datetime as dt import datetime as dt
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import nominatim.api as napi from ..results import AddressLines, ReverseResult, ReverseResults, \
import nominatim.api.v1.classtypes as cl SearchResult, SearchResults
from . import classtypes as cl
#pylint: disable=too-many-branches #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: country_code: Optional[str]) -> None:
parts = {} parts = {}
for line in address: for line in address:
@ -36,7 +37,7 @@ def _write_xml_address(root: ET.Element, address: napi.AddressLines,
ET.SubElement(root, 'country_code').text = country_code 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: root: ET.Element, simple: bool) -> ET.Element:
place = ET.SubElement(root, 'result' if simple else 'place') place = ET.SubElement(root, 'result' if simple else 'place')
if result.place_id is not None: if result.place_id is not None:
@ -82,7 +83,7 @@ def _create_base_entry(result: Union[napi.ReverseResult, napi.SearchResult],
return place return place
def format_base_xml(results: Union[napi.ReverseResults, napi.SearchResults], def format_base_xml(results: Union[ReverseResults, SearchResults],
options: Mapping[str, Any], options: Mapping[str, Any],
simple: bool, xml_root_tag: str, simple: bool, xml_root_tag: str,
xml_extra_info: Mapping[str, str]) -> str: xml_extra_info: Mapping[str, str]) -> str:

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper function for parsing parameters and and outputting data Helper function for parsing parameters and and outputting data
@ -12,8 +12,8 @@ from typing import Tuple, Optional, Any, Dict, Iterable
from itertools import chain from itertools import chain
import re import re
from nominatim.api.results import SearchResult, SearchResults, SourceTable from ..results import SearchResult, SearchResults, SourceTable
from nominatim.api.types import SearchDetails, GeometryFormat from ..types import SearchDetails, GeometryFormat
REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea
4, 4, # 3-4 Country 4, 4, # 3-4 Country

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Generic part of the server implementation of the v1 API. Generic part of the server implementation of the v1 API.
@ -17,13 +17,17 @@ from urllib.parse import urlencode
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.config import Configuration from nominatim_core.config import Configuration
import nominatim.api as napi from .. import logging as loglib
import nominatim.api.logging as loglib from ..core import NominatimAPIAsync
from nominatim.api.v1.format import dispatch as formatting from .format import dispatch as formatting
from nominatim.api.v1.format import RawDataList from .format import RawDataList
from nominatim.api.v1 import helpers 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_TEXT = 'text/plain; charset=utf-8'
CONTENT_XML = 'text/xml; charset=utf-8' CONTENT_XML = 'text/xml; charset=utf-8'
@ -211,16 +215,16 @@ class ASGIAdaptor(abc.ABC):
return False return False
def get_layers(self) -> Optional[napi.DataLayer]: def get_layers(self) -> Optional[DataLayer]:
""" Return a parsed version of the layer parameter. """ Return a parsed version of the layer parameter.
""" """
param = self.get('layer', None) param = self.get('layer', None)
if param is None: if param is None:
return None return None
return cast(napi.DataLayer, return cast(DataLayer,
reduce(napi.DataLayer.__or__, reduce(DataLayer.__or__,
(getattr(napi.DataLayer, s.upper()) for s in param.split(',')))) (getattr(DataLayer, s.upper()) for s in param.split(','))))
def parse_format(self, result_type: Type[Any], default: str) -> str: def parse_format(self, result_type: Type[Any], default: str) -> str:
@ -243,19 +247,19 @@ class ASGIAdaptor(abc.ABC):
""" Create details structure from the supplied geometry parameters. """ Create details structure from the supplied geometry parameters.
""" """
numgeoms = 0 numgeoms = 0
output = napi.GeometryFormat.NONE output = GeometryFormat.NONE
if self.get_bool('polygon_geojson', False): if self.get_bool('polygon_geojson', False):
output |= napi.GeometryFormat.GEOJSON output |= GeometryFormat.GEOJSON
numgeoms += 1 numgeoms += 1
if fmt not in ('geojson', 'geocodejson'): if fmt not in ('geojson', 'geocodejson'):
if self.get_bool('polygon_text', False): if self.get_bool('polygon_text', False):
output |= napi.GeometryFormat.TEXT output |= GeometryFormat.TEXT
numgeoms += 1 numgeoms += 1
if self.get_bool('polygon_kml', False): if self.get_bool('polygon_kml', False):
output |= napi.GeometryFormat.KML output |= GeometryFormat.KML
numgeoms += 1 numgeoms += 1
if self.get_bool('polygon_svg', False): if self.get_bool('polygon_svg', False):
output |= napi.GeometryFormat.SVG output |= GeometryFormat.SVG
numgeoms += 1 numgeoms += 1
if numgeoms > self.config().get_int('POLYGON_OUTPUT_MAX_TYPES'): if numgeoms > self.config().get_int('POLYGON_OUTPUT_MAX_TYPES'):
@ -267,12 +271,12 @@ class ASGIAdaptor(abc.ABC):
} }
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. """ Server glue for /status endpoint. See API docs for details.
""" """
result = await api.status() result = await api.status()
fmt = params.parse_format(napi.StatusResult, 'text') fmt = params.parse_format(StatusResult, 'text')
if fmt == 'text' and result.status: if fmt == 'text' and result.status:
status_code = 500 status_code = 500
@ -283,32 +287,32 @@ async def status_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
status=status_code) 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. """ 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_id = params.get_int('place_id', 0)
place: napi.PlaceRef place: PlaceRef
if place_id: if place_id:
place = napi.PlaceID(place_id) place = PlaceID(place_id)
else: else:
osmtype = params.get('osmtype') osmtype = params.get('osmtype')
if osmtype is None: if osmtype is None:
params.raise_error("Missing ID parameter 'place_id' or 'osmtype'.") 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() 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, result = await api.details(place,
address_details=params.get_bool('addressdetails', False), address_details=params.get_bool('addressdetails', False),
linked_places=params.get_bool('linkedplaces', True), linked_places=params.get_bool('linkedplaces', True),
parented_places=params.get_bool('hierarchy', False), parented_places=params.get_bool('hierarchy', False),
keywords=params.get_bool('keywords', False), keywords=params.get_bool('keywords', False),
geometry_output = napi.GeometryFormat.GEOJSON geometry_output = GeometryFormat.GEOJSON
if params.get_bool('polygon_geojson', False) if params.get_bool('polygon_geojson', False)
else napi.GeometryFormat.NONE, else GeometryFormat.NONE,
locales=locales locales=locales
) )
@ -326,17 +330,17 @@ async def details_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) ->
return params.build_response(output, num_results=1) 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. """ 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() 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 = params.parse_geometry_details(fmt)
details['max_rank'] = helpers.zoom_to_rank(params.get_int('zoom', 18)) details['max_rank'] = helpers.zoom_to_rank(params.get_int('zoom', 18))
details['layers'] = params.get_layers() 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) result = await api.reverse(coord, **details)
@ -357,25 +361,25 @@ async def reverse_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) ->
'namedetails': params.get_bool('namedetails', False), 'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)} '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) fmt, fmt_options)
return params.build_response(output, num_results=1 if result else 0) 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. """ 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() debug = params.setup_debugging()
details = params.parse_geometry_details(fmt) 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 = [] places = []
for oid in (params.get('osm_ids') or '').split(','): for oid in (params.get('osm_ids') or '').split(','):
oid = oid.strip() oid = oid.strip()
if len(oid) > 1 and oid[0] in 'RNWrnw' and oid[1:].isdigit(): 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'): if len(places) > params.config().get_int('LOOKUP_MAX_COUNT'):
params.raise_error('Too many object IDs.') params.raise_error('Too many object IDs.')
@ -383,7 +387,7 @@ async def lookup_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
if places: if places:
results = await api.lookup(places, **details) results = await api.lookup(places, **details)
else: else:
results = napi.SearchResults() results = SearchResults()
if debug: if debug:
return params.build_response(loglib.get_and_disable(), num_results=len(results)) return params.build_response(loglib.get_and_disable(), num_results=len(results))
@ -397,28 +401,28 @@ async def lookup_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
return params.build_response(output, num_results=len(results)) return params.build_response(output, num_results=len(results))
async def _unstructured_search(query: str, api: napi.NominatimAPIAsync, async def _unstructured_search(query: str, api: NominatimAPIAsync,
details: Dict[str, Any]) -> napi.SearchResults: details: Dict[str, Any]) -> SearchResults:
if not query: if not query:
return napi.SearchResults() return SearchResults()
# Extract special format for coordinates from query. # Extract special format for coordinates from query.
query, x, y = helpers.extract_coords_from_query(query) query, x, y = helpers.extract_coords_from_query(query)
if x is not None: if x is not None:
assert y is not None assert y is not None
details['near'] = napi.Point(x, y) details['near'] = Point(x, y)
details['near_radius'] = 0.1 details['near_radius'] = 0.1
# If no query is left, revert to reverse search. # If no query is left, revert to reverse search.
if x is not None and not query: if x is not None and not query:
result = await api.reverse(details['near'], **details) result = await api.reverse(details['near'], **details)
if not result: if not result:
return napi.SearchResults() return SearchResults()
return napi.SearchResults( return SearchResults(
[napi.SearchResult(**{f.name: getattr(result, f.name) [SearchResult(**{f.name: getattr(result, f.name)
for f in dataclasses.fields(napi.SearchResult) for f in dataclasses.fields(SearchResult)
if hasattr(result, f.name)})]) if hasattr(result, f.name)})])
query, cls, typ = helpers.extract_category_from_query(query) query, cls, typ = helpers.extract_category_from_query(query)
if cls is not None: if cls is not None:
@ -428,10 +432,10 @@ async def _unstructured_search(query: str, api: napi.NominatimAPIAsync,
return await api.search(query, **details) 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. """ 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() debug = params.setup_debugging()
details = params.parse_geometry_details(fmt) details = params.parse_geometry_details(fmt)
@ -448,11 +452,11 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
details['min_rank'], details['max_rank'] = \ details['min_rank'], details['max_rank'] = \
helpers.feature_type_to_rank(params.get('featureType', '')) helpers.feature_type_to_rank(params.get('featureType', ''))
if params.get('featureType', None) is not None: if params.get('featureType', None) is not None:
details['layers'] = napi.DataLayer.ADDRESS details['layers'] = DataLayer.ADDRESS
else: else:
details['layers'] = params.get_layers() 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 # unstructured query parameters
query = params.get('q', None) query = params.get('q', None)
@ -508,7 +512,7 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
return params.build_response(output, num_results=len(results)) 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. """ Server glue for /deletable endpoint.
This is a special endpoint that shows polygons that have been This is a special endpoint that shows polygons that have been
deleted or are broken in the OSM data but are kept in the deleted or are broken in the OSM data but are kept in the
@ -528,7 +532,7 @@ async def deletable_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -
return params.build_response(formatting.format_result(results, fmt, {})) 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. """ Server glue for /polygons endpoint.
This is a special endpoint that shows polygons that have changed This is a special endpoint that shows polygons that have changed
their size but are kept in the Nominatim database with their their size but are kept in the Nominatim database with their
@ -560,7 +564,7 @@ async def polygons_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) ->
return params.build_response(formatting.format_result(results, fmt, {})) return params.build_response(formatting.format_result(results, fmt, {}))
EndpointFunc = Callable[[napi.NominatimAPIAsync, ASGIAdaptor], Any] EndpointFunc = Callable[[NominatimAPIAsync, ASGIAdaptor], Any]
ROUTES = [ ROUTES = [
('status', status_endpoint), ('status', status_endpoint),

View File

@ -0,0 +1,11 @@
# 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'

View File

@ -1,4 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # This file is part of Nominatim. (https://nominatim.org)
# #
@ -19,9 +19,9 @@ import yaml
from dotenv import dotenv_values from dotenv import dotenv_values
from psycopg2.extensions import parse_dsn from psycopg2.extensions import parse_dsn
from nominatim.typing import StrPath from .typing import StrPath
from nominatim.errors import UsageError from .errors import UsageError
import nominatim.paths from . import paths
LOG = logging.getLogger() LOG = logging.getLogger()
CONFIG_CACHE : Dict[str, Any] = {} CONFIG_CACHE : Dict[str, Any] = {}
@ -62,7 +62,7 @@ class Configuration:
environ: Optional[Mapping[str, str]] = None) -> None: environ: Optional[Mapping[str, str]] = None) -> None:
self.environ = environ or os.environ self.environ = environ or os.environ
self.project_dir = project_dir 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')) self._config = dotenv_values(str(self.config_dir / 'env.defaults'))
if self.project_dir is not None and (self.project_dir / '.env').is_file(): if self.project_dir is not None and (self.project_dir / '.env').is_file():
self.project_dir = self.project_dir.resolve() self.project_dir = self.project_dir.resolve()
@ -71,9 +71,9 @@ class Configuration:
class _LibDirs: class _LibDirs:
module: Path module: Path
osm2pgsql: Path osm2pgsql: Path
php = nominatim.paths.PHPLIB_DIR php = paths.PHPLIB_DIR
sql = nominatim.paths.SQLLIB_DIR sql = paths.SQLLIB_DIR
data = nominatim.paths.DATA_DIR data = paths.DATA_DIR
self.lib_dir = _LibDirs() self.lib_dir = _LibDirs()
self._private_plugins: Dict[str, object] = {} self._private_plugins: Dict[str, object] = {}

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" Non-blocking database connections. """ Non-blocking database connections.
""" """
@ -22,7 +22,7 @@ try:
except ImportError: except ImportError:
__has_psycopg2_errors__ = False __has_psycopg2_errors__ = False
from nominatim.typing import T_cursor, Query from ..typing import T_cursor, Query
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Import the base library to use with asynchronous SQLAlchemy. Import the base library to use with asynchronous SQLAlchemy.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Specialised connection and cursor functions. Specialised connection and cursor functions.
@ -17,8 +17,8 @@ import psycopg2.extensions
import psycopg2.extras import psycopg2.extras
from psycopg2 import sql as pysql from psycopg2 import sql as pysql
from nominatim.typing import SysEnv, Query, T_cursor from ..typing import SysEnv, Query, T_cursor
from nominatim.errors import UsageError from ..errors import UsageError
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,15 +1,15 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Query and access functions for the in-database property table. Query and access functions for the in-database property table.
""" """
from typing import Optional, cast 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: def set_property(conn: Connection, name: str, value: str) -> None:
""" Add or replace the property with the given name. """ Add or replace the property with the given name.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Preprocessing of SQL files. Preprocessing of SQL files.
@ -10,9 +10,9 @@ Preprocessing of SQL files.
from typing import Set, Dict, Any, cast from typing import Set, Dict, Any, cast
import jinja2 import jinja2
from nominatim.db.connection import Connection from .connection import Connection
from nominatim.db.async_connection import WorkerPool from .async_connection import WorkerPool
from nominatim.config import Configuration from ..config import Configuration
def _get_partitions(conn: Connection) -> Set[int]: def _get_partitions(conn: Connection) -> Set[int]:
""" Get the set of partitions currently in use. """ Get the set of partitions currently in use.

View File

@ -2,15 +2,14 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
SQLAlchemy definitions for all tables used by the frontend. SQLAlchemy definitions for all tables used by the frontend.
""" """
import sqlalchemy as sa import sqlalchemy as sa
import nominatim.db.sqlalchemy_functions #pylint: disable=unused-import from .sqlalchemy_types import Geometry, KeyValueStore, IntArray
from nominatim.db.sqlalchemy_types import Geometry, KeyValueStore, IntArray
#pylint: disable=too-many-instance-attributes #pylint: disable=too-many-instance-attributes
class SearchTables: class SearchTables:

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Module with custom types for SQLAlchemy Module with custom types for SQLAlchemy

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Custom types for SQLAlchemy. Custom types for SQLAlchemy.
@ -15,7 +15,7 @@ import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles from sqlalchemy.ext.compiler import compiles
from sqlalchemy import types from sqlalchemy import types
from nominatim.typing import SaColumn, SaBind from ...typing import SaColumn, SaBind
#pylint: disable=all #pylint: disable=all

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Custom type for an array of integers. Custom type for an array of integers.
@ -13,7 +13,7 @@ import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.dialects.postgresql import ARRAY
from nominatim.typing import SaDialect, SaColumn from ...typing import SaDialect, SaColumn
# pylint: disable=all # pylint: disable=all

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Common json type for different dialects. Common json type for different dialects.
@ -13,7 +13,7 @@ import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.sqlite import JSON as sqlite_json from sqlalchemy.dialects.sqlite import JSON as sqlite_json
from nominatim.typing import SaDialect from ...typing import SaDialect
# pylint: disable=all # pylint: disable=all

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
A custom type that implements a simple key-value store of strings. A custom type that implements a simple key-value store of strings.
@ -14,7 +14,7 @@ from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql import HSTORE from sqlalchemy.dialects.postgresql import HSTORE
from sqlalchemy.dialects.sqlite import JSON as sqlite_json from sqlalchemy.dialects.sqlite import JSON as sqlite_json
from nominatim.typing import SaDialect, SaColumn from ...typing import SaDialect, SaColumn
# pylint: disable=all # pylint: disable=all

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Access and helper functions for the status and status log table. Access and helper functions for the status and status log table.
@ -12,10 +12,10 @@ import datetime as dt
import logging import logging
import re import re
from nominatim.db.connection import Connection from .connection import Connection
from nominatim.tools.exec_utils import get_url from ..utils.url_utils import get_url
from nominatim.errors import UsageError from ..errors import UsageError
from nominatim.typing import TypedDict from ..typing import TypedDict
LOG = logging.getLogger() LOG = logging.getLogger()
ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S' ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper functions for handling DB accesses. Helper functions for handling DB accesses.
@ -14,8 +14,8 @@ import gzip
import io import io
from pathlib import Path from pathlib import Path
from nominatim.db.connection import get_pg_env, Cursor from .connection import get_pg_env, Cursor
from nominatim.errors import UsageError from ..errors import UsageError
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Custom exception and error classes for Nominatim. Custom exception and error classes for Nominatim.

View File

@ -0,0 +1,15 @@
# 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()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Type definitions for typing annotations. Type definitions for typing annotations.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Functions for computation of centroids. Functions for computation of centroids.

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Streaming JSON encoder. Streaming JSON encoder.

View File

@ -0,0 +1,31 @@
# 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

View File

@ -0,0 +1,11 @@
# 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'

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Command-line interface to the Nominatim functions for import, update, Command-line interface to the Nominatim functions for import, update,
@ -16,12 +16,12 @@ import sys
import argparse import argparse
from pathlib import Path from pathlib import Path
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.tools.exec_utils import run_php_server from nominatim_core.errors import UsageError
from nominatim.errors import UsageError from .tools.exec_utils import run_php_server
from nominatim import clicmd from . import clicmd
from nominatim import version from . import version
from nominatim.clicmd.args import NominatimArgs, Subcommand from .clicmd.args import NominatimArgs, Subcommand
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -0,0 +1,28 @@
# 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

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'add-data' subcommand. Implementation of the 'add-data' subcommand.
@ -13,7 +13,7 @@ import logging
import psutil import psutil
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111
@ -64,8 +64,8 @@ class UpdateAddData:
def run(self, args: NominatimArgs) -> int: def run(self, args: NominatimArgs) -> int:
from nominatim.tokenizer import factory as tokenizer_factory from ..tokenizer import factory as tokenizer_factory
from nominatim.tools import tiger_data, add_osm_data from ..tools import tiger_data, add_osm_data
if args.tiger_data: if args.tiger_data:
tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config) tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'admin' subcommand. Implementation of the 'admin' subcommand.
@ -11,9 +11,9 @@ import logging
import argparse import argparse
import random import random
from nominatim.db.connection import connect import nominatim_api as napi
from nominatim.clicmd.args import NominatimArgs from nominatim_core.db.connection import connect
import nominatim.api as napi from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Subcommand definitions for API calls from the command line. Subcommand definitions for API calls from the command line.
@ -13,12 +13,12 @@ import logging
import json import json
import sys import sys
from nominatim.clicmd.args import NominatimArgs import nominatim_api as napi
import nominatim.api as napi import nominatim_api.v1 as api_output
import nominatim.api.v1 as api_output from nominatim_api.v1.helpers import zoom_to_rank, deduplicate_results
from nominatim.api.v1.helpers import zoom_to_rank, deduplicate_results from nominatim_api.v1.format import dispatch as formatting
from nominatim.api.v1.format import dispatch as formatting import nominatim_api.logging as loglib
import nominatim.api.logging as loglib from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Provides custom functions over command-line arguments. Provides custom functions over command-line arguments.
@ -13,10 +13,10 @@ import logging
from functools import reduce from functools import reduce
from pathlib import Path from pathlib import Path
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.typing import Protocol from nominatim_core.typing import Protocol
import nominatim.api as napi import nominatim_api as napi
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'convert' subcommand. Implementation of the 'convert' subcommand.
@ -12,8 +12,8 @@ import argparse
import asyncio import asyncio
from pathlib import Path from pathlib import Path
from nominatim.clicmd.args import NominatimArgs from nominatim_core.errors import UsageError
from nominatim.errors import UsageError from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'export' subcommand. Implementation of the 'export' subcommand.
@ -16,11 +16,11 @@ import sys
import sqlalchemy as sa import sqlalchemy as sa
from nominatim.clicmd.args import NominatimArgs import nominatim_api as napi
import nominatim.api as napi from nominatim_api.results import create_from_placex_row, ReverseResult, add_result_details
from nominatim.api.results import create_from_placex_row, ReverseResult, add_result_details from nominatim_api.types import LookupDetails
from nominatim.api.types import LookupDetails from nominatim_core.errors import UsageError
from nominatim.errors import UsageError from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,16 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'freeze' subcommand. Implementation of the 'freeze' subcommand.
""" """
import argparse import argparse
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'index' subcommand. Implementation of the 'index' subcommand.
@ -11,9 +11,9 @@ import argparse
import psutil import psutil
from nominatim.db import status from nominatim_core.db import status
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of 'refresh' subcommand. Implementation of 'refresh' subcommand.
@ -12,10 +12,10 @@ import argparse
import logging import logging
from pathlib import Path from pathlib import Path
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.tokenizer.base import AbstractTokenizer from ..tokenizer.base import AbstractTokenizer
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'replication' sub-command. Implementation of the 'replication' sub-command.
@ -14,10 +14,10 @@ import logging
import socket import socket
import time import time
from nominatim.db import status from nominatim_core.db import status
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'import' subcommand. Implementation of the 'import' subcommand.
@ -14,13 +14,13 @@ from pathlib import Path
import psutil import psutil
from nominatim.config import Configuration from nominatim_core.errors import UsageError
from nominatim.db.connection import connect from nominatim_core.config import Configuration
from nominatim.db import status, properties from nominatim_core.db.connection import connect
from nominatim.tokenizer.base import AbstractTokenizer from nominatim_core.db import status, properties
from nominatim.version import NOMINATIM_VERSION from ..tokenizer.base import AbstractTokenizer
from nominatim.clicmd.args import NominatimArgs from ..version import NOMINATIM_VERSION
from nominatim.errors import UsageError from .args import NominatimArgs
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Implementation of the 'special-phrases' command. Implementation of the 'special-phrases' command.
@ -11,12 +11,12 @@ import argparse
import logging import logging
from pathlib import Path from pathlib import Path
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.tools.special_phrases.sp_importer import SPImporter, SpecialPhraseLoader from ..tools.special_phrases.sp_importer import SPImporter, SpecialPhraseLoader
from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader from ..tools.special_phrases.sp_wiki_loader import SPWikiLoader
from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader from ..tools.special_phrases.sp_csv_loader import SPCsvLoader
from nominatim.clicmd.args import NominatimArgs from .args import NominatimArgs
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Functions for importing and managing static country information. Functions for importing and managing static country information.
@ -11,11 +11,11 @@ from typing import Dict, Any, Iterable, Tuple, Optional, Container, overload
from pathlib import Path from pathlib import Path
import psycopg2.extras import psycopg2.extras
from nominatim.db import utils as db_utils from nominatim_core.db import utils as db_utils
from nominatim.db.connection import connect, Connection from nominatim_core.db.connection import connect, Connection
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.tokenizer.base import AbstractTokenizer from ..tokenizer.base import AbstractTokenizer
def _flatten_name_list(names: Any) -> Dict[str, str]: def _flatten_name_list(names: Any) -> Dict[str, str]:
if names is None: if names is None:

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Wrapper around place information the indexer gets from the database and hands to Wrapper around place information the indexer gets from the database and hands to

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Data class for a single name of a place. Data class for a single name of a place.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Functions for formatting postcodes according to their country-specific Functions for formatting postcodes according to their country-specific
@ -11,8 +11,8 @@ format.
from typing import Any, Mapping, Optional, Set, Match from typing import Any, Mapping, Optional, Set, Match
import re import re
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.data import country_info from . import country_info
class CountryPostcodeMatcher: class CountryPostcodeMatcher:
""" Matches and formats a postcode according to a format definition """ Matches and formats a postcode according to a format definition

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Main work horse for indexing (computing addresses) the database. Main work horse for indexing (computing addresses) the database.
@ -13,12 +13,12 @@ import time
import psycopg2.extras import psycopg2.extras
from nominatim.tokenizer.base import AbstractTokenizer from nominatim_core.typing import DictCursorResults
from nominatim.indexer.progress import ProgressLogger from nominatim_core.db.async_connection import DBConnection, WorkerPool
from nominatim.indexer import runners from nominatim_core.db.connection import connect, Connection, Cursor
from nominatim.db.async_connection import DBConnection, WorkerPool from ..tokenizer.base import AbstractTokenizer
from nominatim.db.connection import connect, Connection, Cursor from .progress import ProgressLogger
from nominatim.typing import DictCursorResults from . import runners
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helpers for progress logging. Helpers for progress logging.

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Mix-ins that provide the actual commands for the indexer for various indexing Mix-ins that provide the actual commands for the indexer for various indexing
@ -14,10 +14,10 @@ import functools
from psycopg2 import sql as pysql from psycopg2 import sql as pysql
import psycopg2.extras import psycopg2.extras
from nominatim.data.place_info import PlaceInfo from nominatim_core.typing import Query, DictCursorResult, DictCursorResults, Protocol
from nominatim.tokenizer.base import AbstractAnalyzer from nominatim_core.db.async_connection import DBConnection
from nominatim.db.async_connection import DBConnection from ..data.place_info import PlaceInfo
from nominatim.typing import Query, DictCursorResult, DictCursorResults, Protocol from ..tokenizer.base import AbstractAnalyzer
# pylint: disable=C0111 # pylint: disable=C0111

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Abstract class definitions for tokenizers. These base classes are here Abstract class definitions for tokenizers. These base classes are here
@ -12,10 +12,10 @@ from abc import ABC, abstractmethod
from typing import List, Tuple, Dict, Any, Optional, Iterable from typing import List, Tuple, Dict, Any, Optional, Iterable
from pathlib import Path from pathlib import Path
from nominatim.config import Configuration from nominatim_core.typing import Protocol
from nominatim.db.connection import Connection from nominatim_core.config import Configuration
from nominatim.data.place_info import PlaceInfo from nominatim_core.db.connection import Connection
from nominatim.typing import Protocol from ..data.place_info import PlaceInfo
class AbstractAnalyzer(ABC): class AbstractAnalyzer(ABC):
""" The analyzer provides the functions for analysing names and building """ The analyzer provides the functions for analysing names and building

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Functions for creating a tokenizer or initialising the right one for an Functions for creating a tokenizer or initialising the right one for an
@ -24,11 +24,11 @@ import logging
import importlib import importlib
from pathlib import Path from pathlib import Path
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.db import properties from nominatim_core.db import properties
from nominatim.db.connection import connect from nominatim_core.db.connection import connect
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.tokenizer.base import AbstractTokenizer, TokenizerModule from ..tokenizer.base import AbstractTokenizer, TokenizerModule
LOG = logging.getLogger() LOG = logging.getLogger()

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper class to create ICU rules from a configuration file. Helper class to create ICU rules from a configuration file.
@ -14,14 +14,14 @@ import logging
from icu import Transliterator from icu import Transliterator
from nominatim.config import flatten_config_list, Configuration from nominatim_core.config import flatten_config_list, Configuration
from nominatim.db.properties import set_property, get_property from nominatim_core.db.properties import set_property, get_property
from nominatim.db.connection import Connection from nominatim_core.db.connection import Connection
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.tokenizer.place_sanitizer import PlaceSanitizer from .place_sanitizer import PlaceSanitizer
from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis from .icu_token_analysis import ICUTokenAnalysis
from nominatim.tokenizer.token_analysis.base import AnalysisModule, Analyzer from .token_analysis.base import AnalysisModule, Analyzer
import nominatim.data.country_info from ..data import country_info
LOG = logging.getLogger() LOG = logging.getLogger()
@ -51,7 +51,7 @@ class ICURuleLoader:
config='TOKENIZER_CONFIG') config='TOKENIZER_CONFIG')
# Make sure country information is available to analyzers and sanitizers. # 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.normalization_rules = self._cfg_to_icu_rules(rules, 'normalization')
self.transliteration_rules = self._cfg_to_icu_rules(rules, 'transliteration') self.transliteration_rules = self._cfg_to_icu_rules(rules, 'transliteration')

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Container class collecting all components required to transform an OSM name Container class collecting all components required to transform an OSM name
@ -11,11 +11,11 @@ into a Nominatim token.
from typing import Mapping, Optional, TYPE_CHECKING from typing import Mapping, Optional, TYPE_CHECKING
from icu import Transliterator from icu import Transliterator
from nominatim.tokenizer.token_analysis.base import Analyzer from .token_analysis.base import Analyzer
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Any 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: class ICUTokenAnalysis:
""" Container class collecting the transliterators and token analysis """ Container class collecting the transliterators and token analysis

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Tokenizer implementing normalisation as used before Nominatim 4 but using Tokenizer implementing normalisation as used before Nominatim 4 but using
@ -16,16 +16,16 @@ import logging
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
from nominatim.db.connection import connect, Connection, Cursor from nominatim_core.db.connection import connect, Connection, Cursor
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.db.utils import CopyBuffer from nominatim_core.db.utils import CopyBuffer
from nominatim.db.sql_preprocessor import SQLPreprocessor from nominatim_core.db.sql_preprocessor import SQLPreprocessor
from nominatim.data.place_info import PlaceInfo from ..data.place_info import PlaceInfo
from nominatim.tokenizer.icu_rule_loader import ICURuleLoader from ..data.place_name import PlaceName
from nominatim.tokenizer.place_sanitizer import PlaceSanitizer from .icu_rule_loader import ICURuleLoader
from nominatim.data.place_name import PlaceName from .place_sanitizer import PlaceSanitizer
from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis from .icu_token_analysis import ICUTokenAnalysis
from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer from .base import AbstractAnalyzer, AbstractTokenizer
DBCFG_TERM_NORMALIZATION = "tokenizer_term_normalization" DBCFG_TERM_NORMALIZATION = "tokenizer_term_normalization"

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Tokenizer implementing normalisation as used before Nominatim 4. Tokenizer implementing normalisation as used before Nominatim 4.
@ -20,14 +20,14 @@ from icu import Transliterator
import psycopg2 import psycopg2
import psycopg2.extras import psycopg2.extras
from nominatim.db.connection import connect, Connection from nominatim_core.errors import UsageError
from nominatim.config import Configuration from nominatim_core.db.connection import connect, Connection
from nominatim.db import properties from nominatim_core.config import Configuration
from nominatim.db import utils as db_utils from nominatim_core.db import properties
from nominatim.db.sql_preprocessor import SQLPreprocessor from nominatim_core.db import utils as db_utils
from nominatim.data.place_info import PlaceInfo from nominatim_core.db.sql_preprocessor import SQLPreprocessor
from nominatim.errors import UsageError from ..data.place_info import PlaceInfo
from nominatim.tokenizer.base import AbstractAnalyzer, AbstractTokenizer from .base import AbstractAnalyzer, AbstractTokenizer
DBCFG_NORMALIZATION = "tokenizer_normalization" DBCFG_NORMALIZATION = "tokenizer_normalization"
DBCFG_MAXWORDFREQ = "tokenizer_maxwordfreq" DBCFG_MAXWORDFREQ = "tokenizer_maxwordfreq"

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Handler for cleaning name and address tags in place information before it Handler for cleaning name and address tags in place information before it
@ -10,12 +10,12 @@ is handed to the token analysis.
""" """
from typing import Optional, List, Mapping, Sequence, Callable, Any, Tuple from typing import Optional, List, Mapping, Sequence, Callable, Any, Tuple
from nominatim.errors import UsageError from nominatim_core.errors import UsageError
from nominatim.config import Configuration from nominatim_core.config import Configuration
from nominatim.tokenizer.sanitizers.config import SanitizerConfig from .sanitizers.config import SanitizerConfig
from nominatim.tokenizer.sanitizers.base import SanitizerHandler, ProcessInfo from .sanitizers.base import SanitizerHandler, ProcessInfo
from nominatim.data.place_name import PlaceName from ..data.place_name import PlaceName
from nominatim.data.place_info import PlaceInfo from ..data.place_info import PlaceInfo
class PlaceSanitizer: class PlaceSanitizer:

View File

@ -1,18 +1,18 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-3.0-or-later
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Common data types and protocols for sanitizers. Common data types and protocols for sanitizers.
""" """
from typing import Optional, List, Mapping, Callable from typing import Optional, List, Mapping, Callable
from nominatim.tokenizer.sanitizers.config import SanitizerConfig from nominatim_core.typing import Protocol, Final
from nominatim.data.place_info import PlaceInfo from ...data.place_info import PlaceInfo
from nominatim.data.place_name import PlaceName from ...data.place_name import PlaceName
from nominatim.typing import Protocol, Final from .config import SanitizerConfig
class ProcessInfo: class ProcessInfo:

Some files were not shown because too many files have changed in this diff Show More