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 Mapping, List, Any
12 from nominatim.typing import Protocol
14 class Analyser(Protocol):
15 """ Instance of the token analyser.
18 def normalize(self, name: str) -> str:
19 """ Return the normalized form of the name. This is the standard form
20 from which possible variants for the name can be derived.
23 def get_variants_ascii(self, norm_name: str) -> List[str]:
24 """ Compute the spelling variants for the given normalized name
25 and transliterate the result.
28 class AnalysisModule(Protocol):
29 """ Protocol for analysis modules.
32 def configure(self, rules: Mapping[str, Any], normalization_rules: str) -> Any:
33 """ Prepare the configuration of the analysis module.
34 This function should prepare all data that can be shared
35 between instances of this analyser.
38 def create(self, normalizer: Any, transliterator: Any, config: Any) -> Analyser:
39 """ Create a new instance of the analyser.
40 A separate instance of the analyser is created for each thread
41 when used in multi-threading context.