mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 02:47:59 +00:00
enable flake for Python tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for tokenized query data structures.
|
||||
@@ -11,6 +11,7 @@ import pytest
|
||||
|
||||
from nominatim_api.search import query
|
||||
|
||||
|
||||
class MyToken(query.Token):
|
||||
|
||||
def get_category(self):
|
||||
@@ -21,9 +22,11 @@ def mktoken(tid: int):
|
||||
return MyToken(penalty=3.0, token=tid, count=1, addr_count=1,
|
||||
lookup_word='foo')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def qnode():
|
||||
return query.QueryNode(query.BREAK_PHRASE, query.PHRASE_ANY, 0.0 ,'', '')
|
||||
return query.QueryNode(query.BREAK_PHRASE, query.PHRASE_ANY, 0.0, '', '')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ptype,ttype', [(query.PHRASE_ANY, 'W'),
|
||||
(query.PHRASE_AMENITY, 'Q'),
|
||||
@@ -132,4 +135,3 @@ def test_query_struct_amenity_two_words():
|
||||
assert len(q.get_tokens(query.TokenRange(1, 2), query.TOKEN_PARTIAL)) == 1
|
||||
assert len(q.get_tokens(query.TokenRange(1, 2), query.TOKEN_NEAR_ITEM)) == 0
|
||||
assert len(q.get_tokens(query.TokenRange(1, 2), query.TOKEN_QUALIFIER)) == 1
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from nominatim_api.search.token_assignment import TokenAssignment
|
||||
from nominatim_api.types import SearchDetails
|
||||
import nominatim_api.search.db_searches as dbs
|
||||
|
||||
|
||||
class MyToken(Token):
|
||||
def get_category(self):
|
||||
return 'this', 'that'
|
||||
@@ -36,7 +37,6 @@ def make_query(*args):
|
||||
token=tid, count=1, addr_count=1,
|
||||
lookup_word=word))
|
||||
|
||||
|
||||
return q
|
||||
|
||||
|
||||
@@ -241,8 +241,7 @@ def test_name_and_address():
|
||||
[(2, qmod.TOKEN_PARTIAL, [(2, 'b')]),
|
||||
(2, qmod.TOKEN_WORD, [(101, 'b')])],
|
||||
[(3, qmod.TOKEN_PARTIAL, [(3, 'c')]),
|
||||
(3, qmod.TOKEN_WORD, [(102, 'c')])]
|
||||
)
|
||||
(3, qmod.TOKEN_WORD, [(102, 'c')])])
|
||||
builder = SearchBuilder(q, SearchDetails())
|
||||
|
||||
searches = list(builder.build(TokenAssignment(name=TokenRange(0, 1),
|
||||
@@ -267,8 +266,7 @@ def test_name_and_complex_address():
|
||||
(3, qmod.TOKEN_WORD, [(101, 'bc')])],
|
||||
[(3, qmod.TOKEN_PARTIAL, [(3, 'c')])],
|
||||
[(4, qmod.TOKEN_PARTIAL, [(4, 'd')]),
|
||||
(4, qmod.TOKEN_WORD, [(103, 'd')])]
|
||||
)
|
||||
(4, qmod.TOKEN_WORD, [(103, 'd')])])
|
||||
builder = SearchBuilder(q, SearchDetails())
|
||||
|
||||
searches = list(builder.build(TokenAssignment(name=TokenRange(0, 1),
|
||||
@@ -423,8 +421,8 @@ def test_infrequent_partials_in_name():
|
||||
assert len(search.lookups) == 2
|
||||
assert len(search.rankings) == 2
|
||||
|
||||
assert set((l.column, l.lookup_type.__name__) for l in search.lookups) == \
|
||||
{('name_vector', 'LookupAll'), ('nameaddress_vector', 'Restrict')}
|
||||
assert set((s.column, s.lookup_type.__name__) for s in search.lookups) == \
|
||||
{('name_vector', 'LookupAll'), ('nameaddress_vector', 'Restrict')}
|
||||
|
||||
|
||||
def test_frequent_partials_in_name_and_address():
|
||||
@@ -435,10 +433,10 @@ def test_frequent_partials_in_name_and_address():
|
||||
assert all(isinstance(s, dbs.PlaceSearch) for s in searches)
|
||||
searches.sort(key=lambda s: s.penalty)
|
||||
|
||||
assert set((l.column, l.lookup_type.__name__) for l in searches[0].lookups) == \
|
||||
{('name_vector', 'LookupAny'), ('nameaddress_vector', 'Restrict')}
|
||||
assert set((l.column, l.lookup_type.__name__) for l in searches[1].lookups) == \
|
||||
{('nameaddress_vector', 'LookupAll'), ('name_vector', 'LookupAll')}
|
||||
assert set((s.column, s.lookup_type.__name__) for s in searches[0].lookups) == \
|
||||
{('name_vector', 'LookupAny'), ('nameaddress_vector', 'Restrict')}
|
||||
assert set((s.column, s.lookup_type.__name__) for s in searches[1].lookups) == \
|
||||
{('nameaddress_vector', 'LookupAll'), ('name_vector', 'LookupAll')}
|
||||
|
||||
|
||||
def test_too_frequent_partials_in_name_and_address():
|
||||
@@ -449,5 +447,5 @@ def test_too_frequent_partials_in_name_and_address():
|
||||
assert all(isinstance(s, dbs.PlaceSearch) for s in searches)
|
||||
searches.sort(key=lambda s: s.penalty)
|
||||
|
||||
assert set((l.column, l.lookup_type.__name__) for l in searches[0].lookups) == \
|
||||
{('name_vector', 'LookupAny'), ('nameaddress_vector', 'Restrict')}
|
||||
assert set((s.column, s.lookup_type.__name__) for s in searches[0].lookups) == \
|
||||
{('name_vector', 'LookupAny'), ('nameaddress_vector', 'Restrict')}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for query analyzer for ICU tokenizer.
|
||||
@@ -16,7 +16,8 @@ import nominatim_api.search.query as qmod
|
||||
import nominatim_api.search.icu_tokenizer as tok
|
||||
from nominatim_api.logging import set_log_output, get_and_disable
|
||||
|
||||
async def add_word(conn, word_id, word_token, wtype, word, info = None):
|
||||
|
||||
async def add_word(conn, word_id, word_token, wtype, word, info=None):
|
||||
t = conn.t.meta.tables['word']
|
||||
await conn.execute(t.insert(), {'word_id': word_id,
|
||||
'word_token': word_token,
|
||||
@@ -28,6 +29,7 @@ async def add_word(conn, word_id, word_token, wtype, word, info = None):
|
||||
def make_phrase(query):
|
||||
return [Phrase(qmod.PHRASE_ANY, s) for s in query.split(',')]
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def conn(table_factory):
|
||||
""" Create an asynchronous SQLAlchemy engine for the test DB.
|
||||
@@ -102,8 +104,7 @@ async def test_splitting_in_transliteration(conn):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize('term,order', [('23456', ['P', 'H', 'W', 'w']),
|
||||
('3', ['H', 'W', 'w'])
|
||||
])
|
||||
('3', ['H', 'W', 'w'])])
|
||||
async def test_penalty_postcodes_and_housenumbers(conn, term, order):
|
||||
ana = await tok.create_query_analyzer(conn)
|
||||
|
||||
@@ -120,6 +121,7 @@ async def test_penalty_postcodes_and_housenumbers(conn, term, order):
|
||||
|
||||
assert [t[1] for t in torder] == order
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_category_words_only_at_beginning(conn):
|
||||
ana = await tok.create_query_analyzer(conn)
|
||||
|
||||
@@ -16,6 +16,7 @@ import pytest
|
||||
from nominatim_api.search.postcode_parser import PostcodeParser
|
||||
from nominatim_api.search.query import QueryStruct, PHRASE_ANY, PHRASE_POSTCODE, PHRASE_STREET
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pc_config(project_env):
|
||||
country_file = project_env.project_dir / 'country_settings.yaml'
|
||||
@@ -55,6 +56,7 @@ ky:
|
||||
|
||||
return project_env
|
||||
|
||||
|
||||
def mk_query(inp):
|
||||
query = QueryStruct([])
|
||||
phrase_split = re.split(r"([ ,:'-])", inp)
|
||||
@@ -80,6 +82,7 @@ def test_simple_postcode(pc_config, query, pos):
|
||||
|
||||
assert result == {(pos, pos + 1, '45325'), (pos, pos + 1, '453 25')}
|
||||
|
||||
|
||||
def test_contained_postcode(pc_config):
|
||||
parser = PostcodeParser(pc_config)
|
||||
|
||||
@@ -87,7 +90,6 @@ def test_contained_postcode(pc_config):
|
||||
(0, 2, '12345 DX')}
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize('query,frm,to', [('345987', 0, 1), ('345 987', 0, 2),
|
||||
('Aina 345 987', 1, 3),
|
||||
('Aina 23 345 987 ff', 2, 4)])
|
||||
@@ -98,6 +100,7 @@ def test_postcode_with_space(pc_config, query, frm, to):
|
||||
|
||||
assert result == {(frm, to, '345987')}
|
||||
|
||||
|
||||
def test_overlapping_postcode(pc_config):
|
||||
parser = PostcodeParser(pc_config)
|
||||
|
||||
@@ -131,6 +134,7 @@ def test_postcode_with_non_matching_country_prefix(pc_config):
|
||||
|
||||
assert not parser.parse(mk_query('ky12233'))
|
||||
|
||||
|
||||
def test_postcode_inside_postcode_phrase(pc_config):
|
||||
parser = PostcodeParser(pc_config)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Test data types for search queries.
|
||||
@@ -11,14 +11,15 @@ import pytest
|
||||
|
||||
import nominatim_api.search.query as nq
|
||||
|
||||
|
||||
def test_token_range_equal():
|
||||
assert nq.TokenRange(2, 3) == nq.TokenRange(2, 3)
|
||||
assert not (nq.TokenRange(2, 3) != nq.TokenRange(2, 3))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lop,rop', [((1, 2), (3, 4)),
|
||||
((3, 4), (3, 5)),
|
||||
((10, 12), (11, 12))])
|
||||
((3, 4), (3, 5)),
|
||||
((10, 12), (11, 12))])
|
||||
def test_token_range_unequal(lop, rop):
|
||||
assert not (nq.TokenRange(*lop) == nq.TokenRange(*rop))
|
||||
assert nq.TokenRange(*lop) != nq.TokenRange(*rop)
|
||||
@@ -28,17 +29,17 @@ def test_token_range_lt():
|
||||
assert nq.TokenRange(1, 3) < nq.TokenRange(10, 12)
|
||||
assert nq.TokenRange(5, 6) < nq.TokenRange(7, 8)
|
||||
assert nq.TokenRange(1, 4) < nq.TokenRange(4, 5)
|
||||
assert not(nq.TokenRange(5, 6) < nq.TokenRange(5, 6))
|
||||
assert not(nq.TokenRange(10, 11) < nq.TokenRange(4, 5))
|
||||
assert not (nq.TokenRange(5, 6) < nq.TokenRange(5, 6))
|
||||
assert not (nq.TokenRange(10, 11) < nq.TokenRange(4, 5))
|
||||
|
||||
|
||||
def test_token_rankge_gt():
|
||||
assert nq.TokenRange(3, 4) > nq.TokenRange(1, 2)
|
||||
assert nq.TokenRange(100, 200) > nq.TokenRange(10, 11)
|
||||
assert nq.TokenRange(10, 11) > nq.TokenRange(4, 10)
|
||||
assert not(nq.TokenRange(5, 6) > nq.TokenRange(5, 6))
|
||||
assert not(nq.TokenRange(1, 2) > nq.TokenRange(3, 4))
|
||||
assert not(nq.TokenRange(4, 10) > nq.TokenRange(3, 5))
|
||||
assert not (nq.TokenRange(5, 6) > nq.TokenRange(5, 6))
|
||||
assert not (nq.TokenRange(1, 2) > nq.TokenRange(3, 4))
|
||||
assert not (nq.TokenRange(4, 10) > nq.TokenRange(3, 5))
|
||||
|
||||
|
||||
def test_token_range_unimplemented_ops():
|
||||
@@ -58,8 +59,7 @@ def test_query_extract_words():
|
||||
words = q.extract_words(base_penalty=1.0)
|
||||
|
||||
assert set(words.keys()) \
|
||||
== {'12', 'ab', 'hallo', '12 ab', 'ab 12', '12 ab 12'}
|
||||
== {'12', 'ab', 'hallo', '12 ab', 'ab 12', '12 ab 12'}
|
||||
assert sorted(words['12']) == [nq.TokenRange(0, 1, 1.0), nq.TokenRange(2, 3, 1.0)]
|
||||
assert words['12 ab'] == [nq.TokenRange(0, 2, 1.1)]
|
||||
assert words['hallo'] == [nq.TokenRange(3, 4, 1.0)]
|
||||
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for query analyzer creation.
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from nominatim_api.search.query_analyzer_factory import make_query_analyzer
|
||||
from nominatim_api.search.icu_tokenizer import ICUQueryAnalyzer
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_icu_tokenizer(table_factory, api):
|
||||
table_factory('nominatim_properties',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for running the country searcher.
|
||||
@@ -48,6 +48,7 @@ def test_find_from_placex(apiobj, frontend):
|
||||
assert results[0].place_id == 55
|
||||
assert results[0].accuracy == 0.8
|
||||
|
||||
|
||||
def test_find_from_fallback_countries(apiobj, frontend):
|
||||
apiobj.add_country('ro', 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')
|
||||
apiobj.add_country_name('ro', {'name': 'România'})
|
||||
@@ -87,7 +88,6 @@ class TestCountryParameters:
|
||||
apiobj.add_country('ro', 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')
|
||||
apiobj.add_country_name('ro', {'name': 'România'})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -100,7 +100,6 @@ class TestCountryParameters:
|
||||
assert len(results) == 1
|
||||
assert geom.name.lower() in results[0].geometry
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pid,rids', [(76, [55]), (55, [])])
|
||||
def test_exclude_place_id(self, apiobj, frontend, pid, rids):
|
||||
results = run_search(apiobj, frontend, 0.5, ['yw', 'ro'],
|
||||
@@ -108,7 +107,6 @@ class TestCountryParameters:
|
||||
|
||||
assert [r.place_id for r in results] == rids
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox,rids', [((9, 9, 11, 11), [55]),
|
||||
((-10, -10, -3, -3), [])])
|
||||
def test_bounded_viewbox_in_placex(self, apiobj, frontend, viewbox, rids):
|
||||
@@ -118,9 +116,8 @@ class TestCountryParameters:
|
||||
|
||||
assert [r.place_id for r in results] == rids
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox,numres', [((0, 0, 1, 1), 1),
|
||||
((-10, -10, -3, -3), 0)])
|
||||
((-10, -10, -3, -3), 0)])
|
||||
def test_bounded_viewbox_in_fallback(self, apiobj, frontend, viewbox, numres):
|
||||
results = run_search(apiobj, frontend, 0.5, ['ro'],
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for running the near searcher.
|
||||
@@ -12,8 +12,8 @@ import pytest
|
||||
import nominatim_api as napi
|
||||
from nominatim_api.types import SearchDetails
|
||||
from nominatim_api.search.db_searches import NearSearch, PlaceSearch
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories,\
|
||||
FieldLookup, FieldRanking, RankedTokens
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories, \
|
||||
FieldLookup
|
||||
from nominatim_api.search.db_search_lookups import LookupAll
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ class TestNearSearch:
|
||||
apiobj.add_search_name(101, names=[56], country_code='mx',
|
||||
centroid=(-10.3, 56.9))
|
||||
|
||||
|
||||
def test_near_in_placex(self, apiobj, frontend):
|
||||
apiobj.add_placex(place_id=22, class_='amenity', type='bank',
|
||||
centroid=(5.6001, 4.2994))
|
||||
@@ -91,7 +90,6 @@ class TestNearSearch:
|
||||
|
||||
assert [r.place_id for r in results] == [22]
|
||||
|
||||
|
||||
def test_multiple_types_near_in_placex(self, apiobj, frontend):
|
||||
apiobj.add_placex(place_id=22, class_='amenity', type='bank',
|
||||
importance=0.002,
|
||||
@@ -105,7 +103,6 @@ class TestNearSearch:
|
||||
|
||||
assert [r.place_id for r in results] == [22, 23]
|
||||
|
||||
|
||||
def test_near_in_classtype(self, apiobj, frontend):
|
||||
apiobj.add_placex(place_id=22, class_='amenity', type='bank',
|
||||
centroid=(5.6, 4.34))
|
||||
@@ -118,7 +115,6 @@ class TestNearSearch:
|
||||
|
||||
assert [r.place_id for r in results] == [22]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cc,rid', [('us', 22), ('mx', 23)])
|
||||
def test_restrict_by_country(self, apiobj, frontend, cc, rid):
|
||||
apiobj.add_placex(place_id=22, class_='amenity', type='bank',
|
||||
@@ -138,7 +134,6 @@ class TestNearSearch:
|
||||
|
||||
assert [r.place_id for r in results] == [rid]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('excluded,rid', [(22, 122), (122, 22)])
|
||||
def test_exclude_place_by_id(self, apiobj, frontend, excluded, rid):
|
||||
apiobj.add_placex(place_id=22, class_='amenity', type='bank',
|
||||
@@ -148,13 +143,11 @@ class TestNearSearch:
|
||||
centroid=(5.6001, 4.2994),
|
||||
country_code='us')
|
||||
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [('amenity', 'bank')],
|
||||
details=SearchDetails(excluded=[excluded]))
|
||||
|
||||
assert [r.place_id for r in results] == [rid]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('layer,rids', [(napi.DataLayer.POI, [22]),
|
||||
(napi.DataLayer.MANMADE, [])])
|
||||
def test_with_layer(self, apiobj, frontend, layer, rids):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for running the generic place searcher.
|
||||
@@ -14,12 +14,13 @@ import pytest
|
||||
import nominatim_api as napi
|
||||
from nominatim_api.types import SearchDetails
|
||||
from nominatim_api.search.db_searches import PlaceSearch
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories,\
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories, \
|
||||
FieldLookup, FieldRanking, RankedTokens
|
||||
from nominatim_api.search.db_search_lookups import LookupAll, LookupAny, Restrict
|
||||
|
||||
APIOPTIONS = ['search']
|
||||
|
||||
|
||||
def run_search(apiobj, frontend, global_penalty, lookup, ranking, count=2,
|
||||
hnrs=[], pcs=[], ccodes=[], quals=[],
|
||||
details=SearchDetails()):
|
||||
@@ -55,29 +56,27 @@ class TestNameOnlySearches:
|
||||
def fill_database(self, apiobj):
|
||||
apiobj.add_placex(place_id=100, country_code='us',
|
||||
centroid=(5.6, 4.3))
|
||||
apiobj.add_search_name(100, names=[1,2,10,11], country_code='us',
|
||||
apiobj.add_search_name(100, names=[1, 2, 10, 11], country_code='us',
|
||||
centroid=(5.6, 4.3))
|
||||
apiobj.add_placex(place_id=101, country_code='mx',
|
||||
centroid=(-10.3, 56.9))
|
||||
apiobj.add_search_name(101, names=[1,2,20,21], country_code='mx',
|
||||
apiobj.add_search_name(101, names=[1, 2, 20, 21], country_code='mx',
|
||||
centroid=(-10.3, 56.9))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lookup_type', [LookupAll, Restrict])
|
||||
@pytest.mark.parametrize('rank,res', [([10], [100, 101]),
|
||||
([20], [101, 100])])
|
||||
def test_lookup_all_match(self, apiobj, frontend, lookup_type, rank, res):
|
||||
lookup = FieldLookup('name_vector', [1,2], lookup_type)
|
||||
lookup = FieldLookup('name_vector', [1, 2], lookup_type)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, rank)])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking])
|
||||
|
||||
assert [r.place_id for r in results] == res
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lookup_type', [LookupAll, Restrict])
|
||||
def test_lookup_all_partial_match(self, apiobj, frontend, lookup_type):
|
||||
lookup = FieldLookup('name_vector', [1,20], lookup_type)
|
||||
lookup = FieldLookup('name_vector', [1, 20], lookup_type)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, [21])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking])
|
||||
@@ -88,14 +87,13 @@ class TestNameOnlySearches:
|
||||
@pytest.mark.parametrize('rank,res', [([10], [100, 101]),
|
||||
([20], [101, 100])])
|
||||
def test_lookup_any_match(self, apiobj, frontend, rank, res):
|
||||
lookup = FieldLookup('name_vector', [11,21], LookupAny)
|
||||
lookup = FieldLookup('name_vector', [11, 21], LookupAny)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, rank)])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking])
|
||||
|
||||
assert [r.place_id for r in results] == res
|
||||
|
||||
|
||||
def test_lookup_any_partial_match(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [20], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, [21])])
|
||||
@@ -105,19 +103,17 @@ class TestNameOnlySearches:
|
||||
assert len(results) == 1
|
||||
assert results[0].place_id == 101
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cc,res', [('us', 100), ('mx', 101)])
|
||||
def test_lookup_restrict_country(self, apiobj, frontend, cc, res):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], ccodes=[cc])
|
||||
|
||||
assert [r.place_id for r in results] == [res]
|
||||
|
||||
|
||||
def test_lookup_restrict_placeid(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking],
|
||||
@@ -125,7 +121,6 @@ class TestNameOnlySearches:
|
||||
|
||||
assert [r.place_id for r in results] == [100]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -139,7 +134,6 @@ class TestNameOnlySearches:
|
||||
|
||||
assert geom.name.lower() in results[0].geometry
|
||||
|
||||
|
||||
@pytest.mark.parametrize('factor,npoints', [(0.0, 3), (1.0, 2)])
|
||||
def test_return_simplified_geometry(self, apiobj, frontend, factor, npoints):
|
||||
apiobj.add_placex(place_id=333, country_code='us',
|
||||
@@ -162,7 +156,6 @@ class TestNameOnlySearches:
|
||||
assert result.place_id == 333
|
||||
assert len(geom['coordinates']) == npoints
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox', ['5.0,4.0,6.0,5.0', '5.7,4.0,6.0,5.0'])
|
||||
@pytest.mark.parametrize('wcount,rids', [(2, [100, 101]), (20000, [100])])
|
||||
def test_prefer_viewbox(self, apiobj, frontend, viewbox, wcount, rids):
|
||||
@@ -177,18 +170,16 @@ class TestNameOnlySearches:
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox}))
|
||||
assert [r.place_id for r in results] == rids
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox', ['5.0,4.0,6.0,5.0', '5.55,4.27,5.62,4.31'])
|
||||
def test_force_viewbox(self, apiobj, frontend, viewbox):
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
'bounded_viewbox': True})
|
||||
details = SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
'bounded_viewbox': True})
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [], details=details)
|
||||
assert [r.place_id for r in results] == [100]
|
||||
|
||||
|
||||
def test_prefer_near(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.4, [RankedTokens(0.0, [21])])
|
||||
@@ -202,13 +193,12 @@ class TestNameOnlySearches:
|
||||
results.sort(key=lambda r: -r.importance)
|
||||
assert [r.place_id for r in results] == [100, 101]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('radius', [0.09, 0.11])
|
||||
def test_force_near(self, apiobj, frontend, radius):
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
|
||||
details=SearchDetails.from_kwargs({'near': '5.6,4.3',
|
||||
'near_radius': radius})
|
||||
details = SearchDetails.from_kwargs({'near': '5.6,4.3',
|
||||
'near_radius': radius})
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [], details=details)
|
||||
|
||||
@@ -228,7 +218,7 @@ class TestStreetWithHousenumber:
|
||||
apiobj.add_placex(place_id=1000, class_='highway', type='residential',
|
||||
rank_search=26, rank_address=26,
|
||||
country_code='es')
|
||||
apiobj.add_search_name(1000, names=[1,2,10,11],
|
||||
apiobj.add_search_name(1000, names=[1, 2, 10, 11],
|
||||
search_rank=26, address_rank=26,
|
||||
country_code='es')
|
||||
apiobj.add_placex(place_id=91, class_='place', type='house',
|
||||
@@ -243,26 +233,24 @@ class TestStreetWithHousenumber:
|
||||
apiobj.add_placex(place_id=2000, class_='highway', type='residential',
|
||||
rank_search=26, rank_address=26,
|
||||
country_code='pt')
|
||||
apiobj.add_search_name(2000, names=[1,2,20,21],
|
||||
apiobj.add_search_name(2000, names=[1, 2, 20, 21],
|
||||
search_rank=26, address_rank=26,
|
||||
country_code='pt')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('hnr,res', [('20', [91, 1]), ('20 a', [1]),
|
||||
('21', [2]), ('22', [2, 92]),
|
||||
('24', [93]), ('25', [])])
|
||||
def test_lookup_by_single_housenumber(self, apiobj, frontend, hnr, res):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=[hnr])
|
||||
|
||||
assert [r.place_id for r in results] == res + [1000, 2000]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cc,res', [('es', [2, 1000]), ('pt', [92, 2000])])
|
||||
def test_lookup_with_country_restriction(self, apiobj, frontend, cc, res):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -270,9 +258,8 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == res
|
||||
|
||||
|
||||
def test_lookup_exclude_housenumber_placeid(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -280,9 +267,8 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == [2, 1000, 2000]
|
||||
|
||||
|
||||
def test_lookup_exclude_street_placeid(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -290,9 +276,8 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == [2, 92, 2000]
|
||||
|
||||
|
||||
def test_lookup_only_house_qualifier(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -300,9 +285,8 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == [2, 92]
|
||||
|
||||
|
||||
def test_lookup_only_street_qualifier(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -310,10 +294,9 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == [1000, 2000]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('rank,found', [(26, True), (27, False), (30, False)])
|
||||
def test_lookup_min_rank(self, apiobj, frontend, rank, found):
|
||||
lookup = FieldLookup('name_vector', [1,2], LookupAll)
|
||||
lookup = FieldLookup('name_vector', [1, 2], LookupAll)
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, [lookup], [ranking], hnrs=['22'],
|
||||
@@ -321,7 +304,6 @@ class TestStreetWithHousenumber:
|
||||
|
||||
assert [r.place_id for r in results] == ([2, 92, 1000, 2000] if found else [2, 92])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -343,7 +325,7 @@ def test_very_large_housenumber(apiobj, frontend):
|
||||
apiobj.add_placex(place_id=2000, class_='highway', type='residential',
|
||||
rank_search=26, rank_address=26,
|
||||
country_code='pt')
|
||||
apiobj.add_search_name(2000, names=[1,2],
|
||||
apiobj.add_search_name(2000, names=[1, 2],
|
||||
search_rank=26, address_rank=26,
|
||||
country_code='pt')
|
||||
|
||||
@@ -405,7 +387,6 @@ class TestInterpolations:
|
||||
centroid=(10.0, 10.00001),
|
||||
geometry='LINESTRING(9.995 10.00001, 10.005 10.00001)')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('hnr,res', [('21', [992]), ('22', []), ('23', [991])])
|
||||
def test_lookup_housenumber(self, apiobj, frontend, hnr, res):
|
||||
lookup = FieldLookup('name_vector', [111], LookupAll)
|
||||
@@ -414,7 +395,6 @@ class TestInterpolations:
|
||||
|
||||
assert [r.place_id for r in results] == res + [990]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -429,7 +409,6 @@ class TestInterpolations:
|
||||
assert geom.name.lower() in results[0].geometry
|
||||
|
||||
|
||||
|
||||
class TestTiger:
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -453,7 +432,6 @@ class TestTiger:
|
||||
centroid=(10.0, 10.00001),
|
||||
geometry='LINESTRING(9.995 10.00001, 10.005 10.00001)')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('hnr,res', [('21', [992]), ('22', []), ('23', [991])])
|
||||
def test_lookup_housenumber(self, apiobj, frontend, hnr, res):
|
||||
lookup = FieldLookup('name_vector', [111], LookupAll)
|
||||
@@ -462,7 +440,6 @@ class TestTiger:
|
||||
|
||||
assert [r.place_id for r in results] == res + [990]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -513,15 +490,15 @@ class TestLayersRank30:
|
||||
importance=0.0005,
|
||||
address_rank=0, search_rank=30)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('layer,res', [(napi.DataLayer.ADDRESS, [223]),
|
||||
(napi.DataLayer.POI, [224]),
|
||||
(napi.DataLayer.ADDRESS | napi.DataLayer.POI, [223, 224]),
|
||||
(napi.DataLayer.MANMADE, [225]),
|
||||
(napi.DataLayer.RAILWAY, [226]),
|
||||
(napi.DataLayer.NATURAL, [227]),
|
||||
(napi.DataLayer.MANMADE | napi.DataLayer.NATURAL, [225, 227]),
|
||||
(napi.DataLayer.MANMADE | napi.DataLayer.RAILWAY, [225, 226])])
|
||||
@pytest.mark.parametrize('layer,res',
|
||||
[(napi.DataLayer.ADDRESS, [223]),
|
||||
(napi.DataLayer.POI, [224]),
|
||||
(napi.DataLayer.ADDRESS | napi.DataLayer.POI, [223, 224]),
|
||||
(napi.DataLayer.MANMADE, [225]),
|
||||
(napi.DataLayer.RAILWAY, [226]),
|
||||
(napi.DataLayer.NATURAL, [227]),
|
||||
(napi.DataLayer.MANMADE | napi.DataLayer.NATURAL, [225, 227]),
|
||||
(napi.DataLayer.MANMADE | napi.DataLayer.RAILWAY, [225, 226])])
|
||||
def test_layers_rank30(self, apiobj, frontend, layer, res):
|
||||
lookup = FieldLookup('name_vector', [34], LookupAny)
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for running the POI searcher.
|
||||
"""
|
||||
import pytest
|
||||
|
||||
import nominatim_api as napi
|
||||
from nominatim_api.types import SearchDetails
|
||||
from nominatim_api.search.db_searches import PoiSearch
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories
|
||||
@@ -84,14 +83,12 @@ class TestPoiSearchWithRestrictions:
|
||||
else:
|
||||
self.args = {'near': '34.3, 56.100021', 'near_radius': 0.001}
|
||||
|
||||
|
||||
def test_unrestricted(self, apiobj, frontend):
|
||||
results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5],
|
||||
details=SearchDetails.from_kwargs(self.args))
|
||||
|
||||
assert [r.place_id for r in results] == [1, 2]
|
||||
|
||||
|
||||
def test_restict_country(self, apiobj, frontend):
|
||||
results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5],
|
||||
ccodes=['de', 'nz'],
|
||||
@@ -99,7 +96,6 @@ class TestPoiSearchWithRestrictions:
|
||||
|
||||
assert [r.place_id for r in results] == [2]
|
||||
|
||||
|
||||
def test_restrict_by_viewbox(self, apiobj, frontend):
|
||||
args = {'bounded_viewbox': True, 'viewbox': '34.299,56.0,34.3001,56.10001'}
|
||||
args.update(self.args)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Tests for running the postcode searcher.
|
||||
@@ -15,6 +15,7 @@ from nominatim_api.search.db_searches import PostcodeSearch
|
||||
from nominatim_api.search.db_search_fields import WeightedStrings, FieldLookup, \
|
||||
FieldRanking, RankedTokens
|
||||
|
||||
|
||||
def run_search(apiobj, frontend, global_penalty, pcs, pc_penalties=None,
|
||||
ccodes=[], lookup=[], ranking=[], details=SearchDetails()):
|
||||
if pc_penalties is None:
|
||||
@@ -85,26 +86,24 @@ class TestPostcodeSearchWithAddress:
|
||||
apiobj.add_placex(place_id=1000, class_='place', type='village',
|
||||
rank_search=22, rank_address=22,
|
||||
country_code='ch')
|
||||
apiobj.add_search_name(1000, names=[1,2,10,11],
|
||||
apiobj.add_search_name(1000, names=[1, 2, 10, 11],
|
||||
search_rank=22, address_rank=22,
|
||||
country_code='ch')
|
||||
apiobj.add_placex(place_id=2000, class_='place', type='village',
|
||||
rank_search=22, rank_address=22,
|
||||
country_code='pl')
|
||||
apiobj.add_search_name(2000, names=[1,2,20,21],
|
||||
apiobj.add_search_name(2000, names=[1, 2, 20, 21],
|
||||
search_rank=22, address_rank=22,
|
||||
country_code='pl')
|
||||
|
||||
|
||||
def test_lookup_both(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [1,2], 'restrict')
|
||||
lookup = FieldLookup('name_vector', [1, 2], 'restrict')
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, ['12345'], lookup=[lookup], ranking=[ranking])
|
||||
|
||||
assert [r.place_id for r in results] == [100, 101]
|
||||
|
||||
|
||||
def test_restrict_by_name(self, apiobj, frontend):
|
||||
lookup = FieldLookup('name_vector', [10], 'restrict')
|
||||
|
||||
@@ -112,11 +111,10 @@ class TestPostcodeSearchWithAddress:
|
||||
|
||||
assert [r.place_id for r in results] == [100]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('coord,place_id', [((16.5, 5), 100),
|
||||
((-45.1, 7.004), 101)])
|
||||
def test_lookup_near(self, apiobj, frontend, coord, place_id):
|
||||
lookup = FieldLookup('name_vector', [1,2], 'restrict')
|
||||
lookup = FieldLookup('name_vector', [1, 2], 'restrict')
|
||||
ranking = FieldRanking('name_vector', 0.3, [RankedTokens(0.0, [10])])
|
||||
|
||||
results = run_search(apiobj, frontend, 0.1, ['12345'],
|
||||
@@ -126,7 +124,6 @@ class TestPostcodeSearchWithAddress:
|
||||
|
||||
assert [r.place_id for r in results] == [place_id]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON,
|
||||
napi.GeometryFormat.KML,
|
||||
napi.GeometryFormat.SVG,
|
||||
@@ -138,18 +135,16 @@ class TestPostcodeSearchWithAddress:
|
||||
assert results
|
||||
assert all(geom.name.lower() in r.geometry for r in results)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox, rids', [('-46,6,-44,8', [101,100]),
|
||||
('16,4,18,6', [100,101])])
|
||||
@pytest.mark.parametrize('viewbox, rids', [('-46,6,-44,8', [101, 100]),
|
||||
('16,4,18,6', [100, 101])])
|
||||
def test_prefer_viewbox(self, apiobj, frontend, viewbox, rids):
|
||||
results = run_search(apiobj, frontend, 0.1, ['12345'],
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox}))
|
||||
|
||||
assert [r.place_id for r in results] == rids
|
||||
|
||||
|
||||
@pytest.mark.parametrize('viewbox, rid', [('-46,6,-44,8', 101),
|
||||
('16,4,18,6', 100)])
|
||||
('16,4,18,6', 100)])
|
||||
def test_restrict_to_viewbox(self, apiobj, frontend, viewbox, rid):
|
||||
results = run_search(apiobj, frontend, 0.1, ['12345'],
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
@@ -157,7 +152,6 @@ class TestPostcodeSearchWithAddress:
|
||||
|
||||
assert [r.place_id for r in results] == [rid]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('coord,rids', [((17.05, 5), [100, 101]),
|
||||
((-45, 7.1), [101, 100])])
|
||||
def test_prefer_near(self, apiobj, frontend, coord, rids):
|
||||
@@ -166,7 +160,6 @@ class TestPostcodeSearchWithAddress:
|
||||
|
||||
assert [r.place_id for r in results] == rids
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pid,rid', [(100, 101), (101, 100)])
|
||||
def test_exclude(self, apiobj, frontend, pid, rid):
|
||||
results = run_search(apiobj, frontend, 0.1, ['12345'],
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2024 by the Nominatim developer community.
|
||||
# Copyright (C) 2025 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Test for creation of token assignments from tokenized queries.
|
||||
@@ -11,7 +11,10 @@ import pytest
|
||||
|
||||
from nominatim_api.search.query import QueryStruct, Phrase, TokenRange, Token
|
||||
import nominatim_api.search.query as qmod
|
||||
from nominatim_api.search.token_assignment import yield_token_assignments, TokenAssignment, PENALTY_TOKENCHANGE
|
||||
from nominatim_api.search.token_assignment import (yield_token_assignments,
|
||||
TokenAssignment,
|
||||
PENALTY_TOKENCHANGE)
|
||||
|
||||
|
||||
class MyToken(Token):
|
||||
def get_category(self):
|
||||
@@ -102,8 +105,7 @@ def test_multiple_simple_words(btype):
|
||||
TokenAssignment(penalty=penalty, name=TokenRange(1, 3),
|
||||
address=[TokenRange(0, 1)]),
|
||||
TokenAssignment(penalty=penalty, name=TokenRange(2, 3),
|
||||
address=[TokenRange(0, 2)])
|
||||
)
|
||||
address=[TokenRange(0, 2)]))
|
||||
|
||||
|
||||
def test_multiple_words_respect_phrase_break():
|
||||
@@ -156,6 +158,7 @@ def test_housenumber_and_postcode():
|
||||
address=[TokenRange(0, 1), TokenRange(2, 3)],
|
||||
postcode=TokenRange(3, 4)))
|
||||
|
||||
|
||||
def test_postcode_and_housenumber():
|
||||
q = make_query((qmod.BREAK_START, qmod.PHRASE_ANY, [(1, qmod.TOKEN_PARTIAL)]),
|
||||
(qmod.BREAK_WORD, qmod.PHRASE_ANY, [(2, qmod.TOKEN_POSTCODE)]),
|
||||
@@ -211,11 +214,11 @@ def test_housenumber_many_phrases():
|
||||
check_assignments(yield_token_assignments(q),
|
||||
TokenAssignment(penalty=0.1,
|
||||
name=TokenRange(4, 5),
|
||||
housenumber=TokenRange(3, 4),\
|
||||
housenumber=TokenRange(3, 4),
|
||||
address=[TokenRange(0, 1), TokenRange(1, 2),
|
||||
TokenRange(2, 3)]),
|
||||
TokenAssignment(penalty=0.1,
|
||||
housenumber=TokenRange(3, 4),\
|
||||
housenumber=TokenRange(3, 4),
|
||||
address=[TokenRange(0, 1), TokenRange(1, 2),
|
||||
TokenRange(2, 3), TokenRange(4, 5)]))
|
||||
|
||||
@@ -299,7 +302,6 @@ def test_qualifier_at_beginning():
|
||||
(qmod.BREAK_WORD, qmod.PHRASE_ANY, [(2, qmod.TOKEN_PARTIAL)]),
|
||||
(qmod.BREAK_WORD, qmod.PHRASE_ANY, [(3, qmod.TOKEN_PARTIAL)]))
|
||||
|
||||
|
||||
check_assignments(yield_token_assignments(q),
|
||||
TokenAssignment(penalty=0.1, name=TokenRange(1, 3),
|
||||
qualifier=TokenRange(0, 1)),
|
||||
@@ -315,7 +317,6 @@ def test_qualifier_after_name():
|
||||
(qmod.BREAK_WORD, qmod.PHRASE_ANY, [(4, qmod.TOKEN_PARTIAL)]),
|
||||
(qmod.BREAK_WORD, qmod.PHRASE_ANY, [(5, qmod.TOKEN_PARTIAL)]))
|
||||
|
||||
|
||||
check_assignments(yield_token_assignments(q),
|
||||
TokenAssignment(penalty=0.2, name=TokenRange(0, 2),
|
||||
qualifier=TokenRange(2, 3),
|
||||
@@ -349,4 +350,3 @@ def test_qualifier_in_middle_of_phrase():
|
||||
(qmod.BREAK_PHRASE, qmod.PHRASE_ANY, [(5, qmod.TOKEN_PARTIAL)]))
|
||||
|
||||
check_assignments(yield_token_assignments(q))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user