Repository navigation
fix(partition): classify text as an address only when all of it is one - #4630
Conversation
Signed-off-by: Eapp1e <[email protected]>
cragwolfe
left a comment
There was a problem hiding this comment.
Reviewed commit 1260f8490f022c99ee57e2e77832ba397c53a986 against base e5dafa419b2b66d98da892b28f6fb38eb573c1d0 with GPT Pro. No actionable correctness defect found in the change, address regex, text/HTML/DOCX callers, or the two changed test files. Whole-value matching fixes the reported sentence classification; standalone addresses and ZIP+4 remain accepted.
Maintainer decision required — compatibility: this also changes Doylestown, PA 18901. and Doylestown, PA 18901, USA from address matches to nonmatches. The shared text, HTML, and DOCX heuristics can consequently emit a different element type for these address lines. This follows from requiring the entire stripped candidate to satisfy the existing grammar, but consumers may depend on the previous classification. Please decide whether to accept this narrower behavior or explicitly support selected suffixes with a bounded grammar and regression tests. Restoring arbitrary prefix matching would restore the reported bug. This is a compatibility decision, not a demonstrated implementation defect; approval is withheld pending that decision.
All 50 reported check runs on this exact commit succeeded. No local tests were run. Changelog and package-version paths are unchanged versus current main; neither was included in the GPT Pro source scope. This review does not establish integration readiness.
(authored by codex)
Summary
is_us_city_state_zip()matches the start of the text instead of the whole text, so any sentence whose prefix is a city/state/zip is typedAddress.partition_text(),partition_html()andpartition_docx()all call this check beforeis_possible_narrative_text(), so a full sentence turns into anAddresselement:The docstring of the function describes a whole city/state/zip value, and every example it lists is a bare address. Its sibling
is_email_address()was switched tofullmatchin #4577 for the same reason ("classify text as an email address only when all of it is one"); this one kept the start-only match.Change
unstructured/partition/text_type.py:US_CITY_STATE_ZIP_RE.match(...)->US_CITY_STATE_ZIP_RE.fullmatch(...).test_unstructured/partition/test_text_type.py: two parametrized cases that start with an address but continue as a sentence.test_unstructured/partition/test_text.py: onepartition_text()regression test asserting the sentence is not typedAddress.The pattern in
unstructured/nlp/patterns.pyis not anchored, so every bare-address case keeps working: the eleven existing parametrized cases intest_text_type.pyreturn identical results under both calls, andpartition_text(filename="example-docs/fake-text.txt")still yieldsAddress | Doylestown, PA 18901.Test
Fixes #4629