]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/search/test_token_assignment.py
only print non-empty search tables
[nominatim.git] / test / python / api / search / test_token_assignment.py
index 8cbcccb90d675f512f50fe9b2e8699623e025be3..dc123403ab24185aa78e59d842cecb0bce48e296 100644 (file)
@@ -29,7 +29,7 @@ def make_query(*args):
 
         start = len(q.nodes) - 1
         for end, ttype in tlist:
 
         start = len(q.nodes) - 1
         for end, ttype in tlist:
-            q.add_token(TokenRange(start, end), ttype, [dummy])
+            q.add_token(TokenRange(start, end), ttype, dummy)
 
     q.add_node(BreakType.END, PhraseType.NONE)
 
 
     q.add_node(BreakType.END, PhraseType.NONE)
 
@@ -125,6 +125,8 @@ def test_housenumber_and_street():
 
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(1, 2),
 
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(1, 2),
+                                      housenumber=TokenRange(0, 1)),
+                      TokenAssignment(address=[TokenRange(1, 2)],
                                       housenumber=TokenRange(0, 1)))
 
 
                                       housenumber=TokenRange(0, 1)))
 
 
@@ -134,6 +136,8 @@ def test_housenumber_and_street_backwards():
 
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(0, 1),
 
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(0, 1),
+                                      housenumber=TokenRange(1, 2)),
+                      TokenAssignment(address=[TokenRange(0, 1)],
                                       housenumber=TokenRange(1, 2)))
 
 
                                       housenumber=TokenRange(1, 2)))
 
 
@@ -148,6 +152,10 @@ def test_housenumber_and_postcode():
                                       name=TokenRange(0, 1),
                                       housenumber=TokenRange(1, 2),
                                       address=[TokenRange(2, 3)],
                                       name=TokenRange(0, 1),
                                       housenumber=TokenRange(1, 2),
                                       address=[TokenRange(2, 3)],
+                                      postcode=TokenRange(3, 4)),
+                      TokenAssignment(penalty=pytest.approx(0.3),
+                                      housenumber=TokenRange(1, 2),
+                                      address=[TokenRange(0, 1), TokenRange(2, 3)],
                                       postcode=TokenRange(3, 4)))
 
 def test_postcode_and_housenumber():
                                       postcode=TokenRange(3, 4)))
 
 def test_postcode_and_housenumber():
@@ -161,6 +169,10 @@ def test_postcode_and_housenumber():
                                       name=TokenRange(2, 3),
                                       housenumber=TokenRange(3, 4),
                                       address=[TokenRange(0, 1)],
                                       name=TokenRange(2, 3),
                                       housenumber=TokenRange(3, 4),
                                       address=[TokenRange(0, 1)],
+                                      postcode=TokenRange(1, 2)),
+                      TokenAssignment(penalty=pytest.approx(0.3),
+                                      housenumber=TokenRange(3, 4),
+                                      address=[TokenRange(0, 1), TokenRange(2, 3)],
                                       postcode=TokenRange(1, 2)))
 
 
                                       postcode=TokenRange(1, 2)))
 
 
@@ -203,7 +215,11 @@ def test_housenumber_many_phrases():
                                       name=TokenRange(4, 5),
                                       housenumber=TokenRange(3, 4),\
                                       address=[TokenRange(0, 1), TokenRange(1, 2),
                                       name=TokenRange(4, 5),
                                       housenumber=TokenRange(3, 4),\
                                       address=[TokenRange(0, 1), TokenRange(1, 2),
-                                               TokenRange(2, 3)]))
+                                               TokenRange(2, 3)]),
+                      TokenAssignment(penalty=0.1,
+                                      housenumber=TokenRange(3, 4),\
+                                      address=[TokenRange(0, 1), TokenRange(1, 2),
+                                               TokenRange(2, 3), TokenRange(4, 5)]))
 
 
 def test_country_at_beginning():
 
 
 def test_country_at_beginning():
@@ -237,7 +253,7 @@ def test_postcode_with_designation():
                    (BreakType.PHRASE, PhraseType.NONE, [(2, TokenType.PARTIAL)]))
 
     check_assignments(yield_token_assignments(q),
                    (BreakType.PHRASE, PhraseType.NONE, [(2, TokenType.PARTIAL)]))
 
     check_assignments(yield_token_assignments(q),
-                      TokenAssignment(name=TokenRange(1, 2),
+                      TokenAssignment(penalty=0.1, name=TokenRange(1, 2),
                                       postcode=TokenRange(0, 1)),
                       TokenAssignment(postcode=TokenRange(0, 1),
                                       address=[TokenRange(1, 2)]))
                                       postcode=TokenRange(0, 1)),
                       TokenAssignment(postcode=TokenRange(0, 1),
                                       address=[TokenRange(1, 2)]))
@@ -250,7 +266,7 @@ def test_postcode_with_designation_backwards():
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(0, 1),
                                       postcode=TokenRange(1, 2)),
     check_assignments(yield_token_assignments(q),
                       TokenAssignment(name=TokenRange(0, 1),
                                       postcode=TokenRange(1, 2)),
-                      TokenAssignment(postcode=TokenRange(1, 2),
+                      TokenAssignment(penalty=0.1, postcode=TokenRange(1, 2),
                                       address=[TokenRange(0, 1)]))
 
 
                                       address=[TokenRange(0, 1)]))