You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
is_us_city_state_zip() classifies a whole sentence as an Address #4629
is_us_city_state_zip() matches the start of the text instead of the whole text, so a sentence that merely begins with a city/state/zip is typed Address.
The docstring above it says the function "Checks if the given text is in the format of US city/state/zip code" and every example it lists is a bare address. Its sibling is_email_address() was changed to fullmatch in #4577 for exactly this reason ("classify text as an email address only when all of it is one"), and is_us_city_state_zip() was left with the start-only match.
To reproduce
fromunstructured.partition.text_typeimportis_us_city_state_zipis_us_city_state_zip("Doylestown, PA 18901") # True (correct)is_us_city_state_zip("Doylestown, PA 18901 is where we met last spring.") # True (wrong)
partition_text() runs this check before is_possible_narrative_text(), so a whole sentence becomes an Address element:
fromunstructured.partition.textimportpartition_textpartition_text(text="Doylestown, PA 18901 is where the team met last spring.")
# [Address(text='Doylestown, PA 18901 is where the team met last spring.')]
Same entry point in partition_html (unstructured/partition/html/parser.py:1102) and partition_docx (unstructured/partition/docx.py:1178).
Expected behavior
A bare address stays an Address; a sentence that starts with one is classified by the remaining checks (Title / NarrativeText), the same way is_email_address() already behaves.
Additional context
The pattern in unstructured/nlp/patterns.py is not anchored, so fullmatch keeps every existing bare-address case working; the eleven parametrized cases in test_unstructured/partition/test_text_type.py give identical results under both calls.
Activity
fix(partition): classify text as an address only when all of it is one (