mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
custom comparison for SpecialPhrase
Duplicate elemination only works when a custom hash/equal function is implemented that is based on the members.
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
This class is a model used to transfer a special phrase through
|
This class is a model used to transfer a special phrase through
|
||||||
the process of load and importation.
|
the process of load and importation.
|
||||||
"""
|
"""
|
||||||
class SpecialPhrase():
|
class SpecialPhrase:
|
||||||
"""
|
"""
|
||||||
Model representing a special phrase.
|
Model representing a special phrase.
|
||||||
"""
|
"""
|
||||||
@@ -22,3 +22,15 @@ class SpecialPhrase():
|
|||||||
# Needed if some operator in the wiki are not written in english
|
# Needed if some operator in the wiki are not written in english
|
||||||
p_operator = p_operator.strip().lower()
|
p_operator = p_operator.strip().lower()
|
||||||
self.p_operator = '-' if p_operator not in ('near', 'in') else p_operator
|
self.p_operator = '-' if p_operator not in ('near', 'in') else p_operator
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, SpecialPhrase):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return self.p_label == other.p_label \
|
||||||
|
and self.p_class == other.p_class \
|
||||||
|
and self.p_type == other.p_type \
|
||||||
|
and self.p_operator == other.p_operator
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash((self.p_label, self.p_class, self.p_type, self.p_operator))
|
||||||
|
|||||||
@@ -17,11 +17,6 @@ from nominatim.errors import UsageError
|
|||||||
|
|
||||||
from cursor import CursorForTesting
|
from cursor import CursorForTesting
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def testfile_dir(src_dir):
|
|
||||||
return src_dir / 'test' / 'testfiles'
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sp_importer(temp_db_conn, def_config, monkeypatch):
|
def sp_importer(temp_db_conn, def_config, monkeypatch):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import pytest
|
|||||||
|
|
||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
|
from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
|
||||||
|
from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sp_csv_loader(src_dir):
|
def sp_csv_loader(src_dir):
|
||||||
@@ -29,17 +30,11 @@ def test_generate_phrases(sp_csv_loader):
|
|||||||
"""
|
"""
|
||||||
phrases = list(sp_csv_loader.generate_phrases())
|
phrases = list(sp_csv_loader.generate_phrases())
|
||||||
|
|
||||||
assert len(phrases) == 41
|
assert len(phrases) == 42
|
||||||
assert len(set(phrases)) == 41
|
assert len(set(phrases)) == 41
|
||||||
|
|
||||||
assert any(p.p_label == 'Billboard'
|
assert SpecialPhrase('Billboard', 'advertising', 'billboard', '-') in phrases
|
||||||
and p.p_class == 'advertising'
|
assert SpecialPhrase('Zip Lines', 'aerialway', 'zip_line', '-') in phrases
|
||||||
and p.p_type == 'billboard'
|
|
||||||
and p.p_operator == '-' for p in phrases)
|
|
||||||
assert any(p.p_label == 'Zip Lines'
|
|
||||||
and p.p_class == 'aerialway'
|
|
||||||
and p.p_type == 'zip_line'
|
|
||||||
and p.p_operator == '-' for p in phrases)
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_cvs_file():
|
def test_invalid_cvs_file():
|
||||||
|
|||||||
1
test/testdata/sp_csv_test.csv
vendored
1
test/testdata/sp_csv_test.csv
vendored
@@ -18,6 +18,7 @@ Zipline near,aerialway,zip_line,near,N
|
|||||||
Ziplines near,aerialway,zip_line,near,Y
|
Ziplines near,aerialway,zip_line,near,Y
|
||||||
Zipwire,aerialway,zip_line,-,N
|
Zipwire,aerialway,zip_line,-,N
|
||||||
Zipwires,aerialway,zip_line,-,Y
|
Zipwires,aerialway,zip_line,-,Y
|
||||||
|
Zipwires,aerialway,zip_line,name,Y
|
||||||
Zipwire in,aerialway,zip_line,in,N
|
Zipwire in,aerialway,zip_line,in,N
|
||||||
Zipwires in,aerialway,zip_line,in,Y
|
Zipwires in,aerialway,zip_line,in,Y
|
||||||
Zipwire near,aerialway,zip_line,near,N
|
Zipwire near,aerialway,zip_line,near,N
|
||||||
|
|||||||
|
Reference in New Issue
Block a user