1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 This file replaces values based on pre-defined regex rules:
10 from typing import List
13 from .config import QueryConfig
14 from .base import QueryProcessingFunc
15 from ..search.query import Phrase
18 class _GenericPreprocessing:
20 def __init__(self, config: QueryConfig) -> None:
23 def split_phrase(self, phrase: Phrase) -> Phrase:
25 This function performs replacements on the given text using regex patterns.
28 if phrase.text is None:
31 match_patterns = self.config.get('replacements', 'Key not found')
32 for item in match_patterns:
33 phrase.text = re.sub(item['pattern'], item['replace'], phrase.text)
37 def __call__(self, phrases: List[Phrase]) -> List[Phrase]:
38 """Apply regex replacements to the given addresses.
40 return [self.split_phrase(p) for p in phrases]
43 def create(config: QueryConfig) -> QueryProcessingFunc:
44 """ Create a function for generic preprocessing.
46 return _GenericPreprocessing(config)