Refactored min and associated tests to follow greater than or equal to logic, so that min=0 accounted for no filtering

r
This commit is contained in:
anqixxx
2025-05-31 09:41:36 -07:00
parent 40d5b78eb8
commit 20cf4b56b9
2 changed files with 10 additions and 8 deletions

View File

@@ -68,16 +68,17 @@ class SPImporter():
""" """
Returns list of allowed special phrases from the database, Returns list of allowed special phrases from the database,
restricting to a list of combinations of classes and types 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() db_combinations = set()
query = f""" query = f"""
SELECT class AS CLS, type AS typ SELECT class AS CLS, type AS typ
FROM placex FROM placex
GROUP BY class, type GROUP BY class, type
HAVING COUNT(*) > {min} HAVING COUNT(*) >= {min}
""" """
with self.db_connection.cursor() as db_cursor: with self.db_connection.cursor() as db_cursor:
@@ -207,7 +208,8 @@ class SPImporter():
phrase_class = pair[0] phrase_class = pair[0]
phrase_type = pair[1] 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", LOG.warning("Skipping phrase %s=%s: not in allowed special phrases",
phrase_class, phrase_type) phrase_class, phrase_type)
continue continue

View File

@@ -3,8 +3,8 @@ from nominatim_db.tools.special_phrases.sp_importer import SPImporter
# Testing Database Class Pair Retrival using Conftest.py and placex # Testing Database Class Pair Retrival using Conftest.py and placex
def test_get_classtype_pair_data(placex_table, def_config, temp_db_conn): def test_get_classtype_pair_data(placex_table, def_config, temp_db_conn):
for _ in range(101): for _ in range(100):
placex_table.add(cls='highway', typ='motorway') # edge case 101 placex_table.add(cls='highway', typ='motorway') # edge case 100
for _ in range(99): for _ in range(99):
placex_table.add(cls='amenity', typ='prison') # edge case 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): def test_get_classtype_pair_data_more(placex_table, def_config, temp_db_conn):
for _ in range(100): for _ in range(99):
placex_table.add(cls='emergency', typ='firehydrant') # edge case 100, not included placex_table.add(cls='emergency', typ='firehydrant') # edge case 99, not included
for _ in range(199): for _ in range(199):
placex_table.add(cls='amenity', typ='prison') placex_table.add(cls='amenity', typ='prison')