1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Common data types and protocols for analysers.
10 from typing import TypeVar, Mapping, List, Any
12 from typing_extensions import Protocol
15 T_config = TypeVar('T_config') # pylint: disable=invalid-name
17 class Analyser(Protocol):
18 """ Instance of the token analyser.
21 def normalize(self, name: str) -> str:
22 """ Return the normalized form of the name. This is the standard form
23 from which possible variants for the name can be derived.
26 def get_variants_ascii(self, norm_name: str) -> List[str]:
27 """ Compute the spelling variants for the given normalized name
28 and transliterate the result.
31 class AnalysisModule(Protocol[T_config]):
32 """ Protocol for analysis modules.
35 def configure(self, rules: Mapping[str, Any], normalization_rules: str) -> T_config:
36 """ Prepare the configuration of the analysis module.
37 This function should prepare all data that can be shared
38 between instances of this analyser.
41 def create(self, normalizer: Any, transliterator: Any, config: T_config) -> Analyser:
42 """ Create a new instance of the analyser.
43 A separate instance of the analyser is created for each thread
44 when used in multi-threading context.