From 9bc5be837b0bf366306ce526a1a15a2835d8db85 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 21 Jun 2023 11:56:39 +0200 Subject: [PATCH] remove useless check Found by new mypy version. --- nominatim/api/search/icu_tokenizer.py | 7 +++---- nominatim/api/search/legacy_tokenizer.py | 7 +++---- test/python/api/search/test_icu_query_analyzer.py | 4 ++-- test/python/api/search/test_legacy_query_analyzer.py | 5 ++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/nominatim/api/search/icu_tokenizer.py b/nominatim/api/search/icu_tokenizer.py index 17e67905..9bd16e1d 100644 --- a/nominatim/api/search/icu_tokenizer.py +++ b/nominatim/api/search/icu_tokenizer.py @@ -248,12 +248,11 @@ class ICUQueryAnalyzer(AbstractQueryAnalyzer): and (repl.ttype != qmod.TokenType.HOUSENUMBER or len(tlist.tokens[0].lookup_word) > 4): repl.add_penalty(0.39) - elif tlist.ttype == qmod.TokenType.HOUSENUMBER: + elif tlist.ttype == qmod.TokenType.HOUSENUMBER \ + and len(tlist.tokens[0].lookup_word) <= 3: if any(c.isdigit() for c in tlist.tokens[0].lookup_word): for repl in node.starting: - if repl.end == tlist.end and repl.ttype != qmod.TokenType.HOUSENUMBER \ - and (repl.ttype != qmod.TokenType.HOUSENUMBER - or len(tlist.tokens[0].lookup_word) <= 3): + if repl.end == tlist.end and repl.ttype != qmod.TokenType.HOUSENUMBER: repl.add_penalty(0.5 - tlist.tokens[0].penalty) elif tlist.ttype not in (qmod.TokenType.COUNTRY, qmod.TokenType.PARTIAL): norm = parts[i].normalized diff --git a/nominatim/api/search/legacy_tokenizer.py b/nominatim/api/search/legacy_tokenizer.py index 96975704..3346584c 100644 --- a/nominatim/api/search/legacy_tokenizer.py +++ b/nominatim/api/search/legacy_tokenizer.py @@ -233,12 +233,11 @@ class LegacyQueryAnalyzer(AbstractQueryAnalyzer): and (repl.ttype != qmod.TokenType.HOUSENUMBER or len(tlist.tokens[0].lookup_word) > 4): repl.add_penalty(0.39) - elif tlist.ttype == qmod.TokenType.HOUSENUMBER: + elif tlist.ttype == qmod.TokenType.HOUSENUMBER \ + and len(tlist.tokens[0].lookup_word) <= 3: if any(c.isdigit() for c in tlist.tokens[0].lookup_word): for repl in node.starting: - if repl.end == tlist.end and repl.ttype != qmod.TokenType.HOUSENUMBER \ - and (repl.ttype != qmod.TokenType.HOUSENUMBER - or len(tlist.tokens[0].lookup_word) <= 3): + if repl.end == tlist.end and repl.ttype != qmod.TokenType.HOUSENUMBER: repl.add_penalty(0.5 - tlist.tokens[0].penalty) diff --git a/test/python/api/search/test_icu_query_analyzer.py b/test/python/api/search/test_icu_query_analyzer.py index 78cd2c4d..faf81375 100644 --- a/test/python/api/search/test_icu_query_analyzer.py +++ b/test/python/api/search/test_icu_query_analyzer.py @@ -118,10 +118,10 @@ async def test_penalty_postcodes_and_housenumbers(conn, term, order): assert query.num_token_slots() == 1 - torder = [(tl.tokens[0].penalty, tl.ttype) for tl in query.nodes[0].starting] + torder = [(tl.tokens[0].penalty, tl.ttype.name) for tl in query.nodes[0].starting] torder.sort() - assert [t[1] for t in torder] == [TokenType[o] for o in order] + assert [t[1] for t in torder] == order @pytest.mark.asyncio async def test_category_words_only_at_beginning(conn): diff --git a/test/python/api/search/test_legacy_query_analyzer.py b/test/python/api/search/test_legacy_query_analyzer.py index c2115853..cdea6ede 100644 --- a/test/python/api/search/test_legacy_query_analyzer.py +++ b/test/python/api/search/test_legacy_query_analyzer.py @@ -195,11 +195,10 @@ async def test_penalty_postcodes_and_housenumbers(conn, term, order): assert query.num_token_slots() == 1 - torder = [(tl.tokens[0].penalty, tl.ttype) for tl in query.nodes[0].starting] - print(query.nodes[0].starting) + torder = [(tl.tokens[0].penalty, tl.ttype.name) for tl in query.nodes[0].starting] torder.sort() - assert [t[1] for t in torder] == [TokenType[o] for o in order] + assert [t[1] for t in torder] == order @pytest.mark.asyncio -- 2.39.5