Skip to content

fix(partition): classify text as an address only when all of it is one - #4630

Merged
cragwolfe merged 1 commit into
Unstructured-IO:mainfrom
Eapp1e:fix/city-state-zip-full-match
Oct 29, 2026
Merged

cragwolfe merged 1 commit into
Unstructured-IO:mainfrom
Eapp1e:fix/city-state-zip-full-match

Conversation

@Eapp1e

@Eapp1e Eapp1e commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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 typed Address.

partition_text(), partition_html() and partition_docx() all call this check before is_possible_narrative_text(), so a full sentence turns into an Address element:

partition_text(text="Doylestown, PA 18901 is where the team met last spring.")
# [Address(text='Doylestown, PA 18901 is where the team met last spring.')]

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 to fullmatch in #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: one partition_text() regression test asserting the sentence is not typed Address.

The pattern in unstructured/nlp/patterns.py is not anchored, so every bare-address case keeps working: the eleven existing parametrized cases in test_text_type.py return identical results under both calls, and partition_text(filename="example-docs/fake-text.txt") still yields Address | Doylestown, PA 18901.

Test

python -m pytest test_unstructured/partition/test_text_type.py \
  --noconftest -o addopts= -p no:cacheprovider -p stub_tokenize -p stub_oxmsg -q
before: 9 failed, 105 passed   after: 9 failed, 107 passed
(the two new cases flip to pass; the nine failures are offline-env only - spaCy
`en_core_web_sm` is not installed here, so `contains_verb` returns False, and they
fail identically before and after)

python -m pytest test_unstructured/partition/test_text.py ...
before: 35 failed, 56 passed   after: 35 failed, 57 passed
(the new test flips; the rest are FileNotFound / language-model env issues)

python -m pytest test_unstructured/partition/test_text.py \
  -k does_not_make_an_address ...
1 failed before the change, 1 passed after

Fixes #4629

View guided diff

@cragwolfe cragwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@cragwolfe
cragwolfe added this pull request to the merge queue Oct 29, 2026
Merged via the queue into Unstructured-IO:main with commit 0b380d4 Oct 29, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is_us_city_state_zip() classifies a whole sentence as an Address

2 participants