From 20cf4b56b9c0fd8a6c8f91d341143e8d1c815e4e Mon Sep 17 00:00:00 2001 From: anqixxx Date: Sat, 31 May 2025 09:41:36 -0700 Subject: [PATCH] Refactored min and associated tests to follow greater than or equal to logic, so that min=0 accounted for no filtering r --- src/nominatim_db/tools/special_phrases/sp_importer.py | 10 ++++++---- test/python/tools/test_sp_importer.py | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/nominatim_db/tools/special_phrases/sp_importer.py b/src/nominatim_db/tools/special_phrases/sp_importer.py index 6bd3c287..890cf2fc 100644 --- a/src/nominatim_db/tools/special_phrases/sp_importer.py +++ b/src/nominatim_db/tools/special_phrases/sp_importer.py @@ -68,16 +68,17 @@ class SPImporter(): """ Returns list of allowed special phrases from the database, restricting to a list of combinations of classes and types - which occur more than a specified amount of times. + which occur equal to or more than a specified amount of times. - Default value for this, if not specified, is at least once. + Default value for this is 0, which allows everything in database. """ db_combinations = set() + query = f""" SELECT class AS CLS, type AS typ FROM placex GROUP BY class, type - HAVING COUNT(*) > {min} + HAVING COUNT(*) >= {min} """ with self.db_connection.cursor() as db_cursor: @@ -207,7 +208,8 @@ class SPImporter(): phrase_class = pair[0] phrase_type = pair[1] - if (phrase_class, phrase_type) not in allowed_special_phrases: + # Will only filter if min is not 0 + if min and (phrase_class, phrase_type) not in allowed_special_phrases: LOG.warning("Skipping phrase %s=%s: not in allowed special phrases", phrase_class, phrase_type) continue diff --git a/test/python/tools/test_sp_importer.py b/test/python/tools/test_sp_importer.py index dda02f11..c64c2b7d 100644 --- a/test/python/tools/test_sp_importer.py +++ b/test/python/tools/test_sp_importer.py @@ -3,8 +3,8 @@ from nominatim_db.tools.special_phrases.sp_importer import SPImporter # Testing Database Class Pair Retrival using Conftest.py and placex def test_get_classtype_pair_data(placex_table, def_config, temp_db_conn): - for _ in range(101): - placex_table.add(cls='highway', typ='motorway') # edge case 101 + for _ in range(100): + placex_table.add(cls='highway', typ='motorway') # edge case 100 for _ in range(99): placex_table.add(cls='amenity', typ='prison') # edge case 99 @@ -25,8 +25,8 @@ def test_get_classtype_pair_data(placex_table, def_config, temp_db_conn): def test_get_classtype_pair_data_more(placex_table, def_config, temp_db_conn): - for _ in range(100): - placex_table.add(cls='emergency', typ='firehydrant') # edge case 100, not included + for _ in range(99): + placex_table.add(cls='emergency', typ='firehydrant') # edge case 99, not included for _ in range(199): placex_table.add(cls='amenity', typ='prison') -- 2.39.5