]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/query_processing/test_normalize.py
generalize normalization step for search query
[nominatim.git] / test / python / api / query_processing / test_normalize.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for normalizing search queries.
9 """
10 from pathlib import Path
11
12 import pytest
13
14 from icu import Transliterator
15
16 import nominatim_api.search.query as qmod
17 from nominatim_api.query_preprocessing.config import QueryConfig
18 from nominatim_api.query_preprocessing import normalize
19
20 def run_preprocessor_on(query, norm):
21     normalizer = Transliterator.createFromRules("normalization", norm)
22     proc = normalize.create(QueryConfig().set_normalizer(normalizer))
23
24     return proc(query)
25
26
27 def test_normalize_simple():
28     norm = ':: lower();'
29     query = [qmod.Phrase(qmod.PhraseType.NONE, 'Hallo')]
30
31     out = run_preprocessor_on(query, norm)
32
33     assert len(out) == 1
34     assert out == [qmod.Phrase(qmod.PhraseType.NONE, 'hallo')]