X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/612d34930b603997acce2772e7264b509bb8aed6..97ac036df54f5a9e6f1d344e397f4e27aeccda9a:/nominatim/tokenizer/token_analysis/postcodes.py?ds=sidebyside diff --git a/nominatim/tokenizer/token_analysis/postcodes.py b/nominatim/tokenizer/token_analysis/postcodes.py index 18fc2a8d..94e93645 100644 --- a/nominatim/tokenizer/token_analysis/postcodes.py +++ b/nominatim/tokenizer/token_analysis/postcodes.py @@ -8,19 +8,21 @@ Specialized processor for postcodes. Supports a 'lookup' variant of the token, which produces variants with optional spaces. """ +from typing import Any, List from nominatim.tokenizer.token_analysis.generic_mutation import MutationVariantGenerator +from nominatim.data.place_name import PlaceName ### Configuration section -def configure(rules, normalization_rules): # pylint: disable=W0613 +def configure(*_: Any) -> None: """ All behaviour is currently hard-coded. """ return None ### Analysis section -def create(normalizer, transliterator, config): # pylint: disable=W0613 +def create(normalizer: Any, transliterator: Any, config: None) -> 'PostcodeTokenAnalysis': # pylint: disable=W0613 """ Create a new token analysis instance for this module. """ return PostcodeTokenAnalysis(normalizer, transliterator) @@ -30,28 +32,26 @@ class PostcodeTokenAnalysis: """ Special normalization and variant generation for postcodes. This analyser must not be used with anything but postcodes as - it follows some special rules: `normalize` doesn't necessarily - need to return a standard form as per normalization rules. It - needs to return the canonical form of the postcode that is also - used for output. `get_variants_ascii` then needs to ensure that + it follows some special rules: the canonial ID is the form that + is used for the output. `compute_variants` then needs to ensure that the generated variants once more follow the standard normalization and transliteration, so that postcodes are correctly recognised by the search algorithm. """ - def __init__(self, norm, trans): + def __init__(self, norm: Any, trans: Any) -> None: self.norm = norm self.trans = trans self.mutator = MutationVariantGenerator(' ', (' ', '')) - def normalize(self, name): + def get_canonical_id(self, name: PlaceName) -> str: """ Return the standard form of the postcode. """ - return name.strip().upper() + return name.name.strip().upper() - def get_variants_ascii(self, norm_name): + def compute_variants(self, norm_name: str) -> List[str]: """ Compute the spelling variants for the given normalized postcode. Takes the canonical form of the postcode, normalizes it using the