Skip to content

Commit

Permalink
Support inverse occupancy, post-dir in type-first street name
Browse files Browse the repository at this point in the history
  • Loading branch information
lmelninkas committed Apr 23, 2024
1 parent caee8ba commit 16ba3b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pyap/source_US/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def str_list_to_upper_lower_regex(str_list: List[str]) -> str:
street_type_leading_list = ["Camino", "El\ Camino"]


def street_type_list_to_regex(street_type_list):
def street_type_list_to_regex(street_type_list: list[str]) -> str:
"""Converts a list of street types into a regex"""
street_types = str_list_to_upper_lower_regex(street_type_list)

Expand Down Expand Up @@ -803,14 +803,18 @@ def street_type_list_to_regex(street_type_list):
(?:
(?:{street_name_a}{space_div}{street_type_a})
|
(?:{street_type_b}{space_div}{street_name_b})
(?:
(?:{post_direction_re}{space_div})?
{street_type_b}{space_div}{street_name_b}
)
)
""".format(
space_div=space_div,
street_name_a=rf"(?P<street_name_a>{street_name_multi_word_re})",
street_type_a=street_type_extended,
street_type_b=rf"(?P<street_type_b>{street_types_leading_re})",
street_name_b=rf"(?P<street_name_b>{street_name_one_word_re})",
post_direction_re=post_direction_re,
)

floor_indic = r"""
Expand Down Expand Up @@ -893,6 +897,8 @@ def street_type_list_to_regex(street_type_list):
(?:
[A-Za-z\#\&\-\d]{1,7}(?:\s?[SWNE])?
)?
|
\d{2,4}\ [Ss][Tt][Ee](?:\ \*)?
)
|
(?:
Expand Down Expand Up @@ -952,7 +958,7 @@ def street_type_list_to_regex(street_type_list):
|
(?:
{post_direction_re}\
\d{{,3}}[A-Z][A-Za-z\-]{{,31}}
\d{{,3}}[A-Za-z\-]{{1,31}}
)
)
(?:{space_div}{post_direction})?
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parser_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def test_po_box_positive(input, expected):
"input,expected",
[
# positive assertions
("800 W EL CAMINO REAL\n350 STE *", True),
("899 HEATHROW PARK LN", True),
("1806 Dominion Way Ste B", True),
("696 BEAL PKWY", True),
Expand Down Expand Up @@ -479,6 +480,7 @@ def test_full_street_positive(input, expected):
("696 BEAL PKWY NW\nFT WALTON BCH FL 32547", True),
("2633 Camino Ramon Ste. 400 San Ramon, CA 94583-2176", True),
("2951 El Camino Real Palo Alto, CA 94306", True),
("800 W EL CAMINO REAL\n350 STE *\nMOUNTAIN VIEW, CA 94040", True),
("3821 ED DR, RALEIGH, NC 27612", True),
("213 WEST 35TH STREET SUITE, 400, NEW YORK, NY", True),
("326 33RD AVE., EAST, SEATTLE, WA 98112", True),
Expand Down

0 comments on commit 16ba3b4

Please sign in to comment.