Repository navigation
fix(partition): classify text as an email address only when all of it is one - #4577
Merged
cragwolfe merged 2 commits intoOct 22, 2026
Merged
Conversation
… is one is_email_address() used re.match, so the email pattern only had to match at the start of the text. A sentence that begins with an address, such as "[email protected] is the address for every invoice question you have.", became an EmailAddress element in partition_text, partition_html, partition_docx and partition_pptx. Match the whole stripped text instead. Signed-off-by: Christopher Krah <[email protected]>
cragwolfe
approved these changes
Oct 22, 2026
cragwolfe
left a comment
Contributor
There was a problem hiding this comment.
Reviewed exact head 692d3daaddb4e05d9cd4f8307e9949a8824ff537 with GPT Pro. No actionable defects found in the full-string email check, shared partitioner callers, or regression tests. The stricter handling of trailing punctuation and additional text matches the stated whole-value contract; surrounding whitespace remains accepted.
This approval covers the source review. Required exact-head checks (changelog, test_dockerfile, lint (3.12), test_unit (3.12), and test_ingest_src (3.12)) have no reported results; only Socket success/neutral checks are present. GitHub also reports merge conflicts. No tests were run locally.
(authored by codex)
Merged
linhongyu510
pushed a commit
to linhongyu510/unstructured
that referenced
this pull request
Oct 22, 2026
Drops the `-dev6` suffix so 0.27.34 can be tagged and published. There are no code changes. Since 0.27.33, this release contains: - Free decode buffers sooner when restoring original elements (Unstructured-IO#4524) - Free image buffers sooner during figure extraction (Unstructured-IO#4523) - Honor `encoding=` in `partition_json` and `partition_ndjson` (Unstructured-IO#4483) - Read a PowerPoint line break as a newline (Unstructured-IO#4571) - Drop the empty entry of an email address group (Unstructured-IO#4576) - Read CSV and TSV cells as the file holds them (Unstructured-IO#4574) - Classify text as an email address only when all of it is one (Unstructured-IO#4577) After merge, create the `0.27.34` GitHub release from the merge commit. That publishes to PyPI. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4582?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This was referenced Oct 29, 2026
ayam04
pushed a commit
to ayam04/unstructured
that referenced
this pull request
Oct 30, 2026
Unstructured-IO#4630) ## 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: ```python 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 Unstructured-IO#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 ```text 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 Unstructured-IO#4629 <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4630?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Signed-off-by: Eapp1e <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The docstring of
is_email_address()says it checks whether the text "is the email address" (unstructured/partition/text_type.py:319). But line 320 callsEMAIL_ADDRESS_PATTERN_RE.match, so only the start of the text must be an address.partition_text,partition_html,partition_docxandpartition_pptxall send text through this check.On this branch the same probe prints
['NarrativeText']for all four. The change isfullmatchon the stripped text, with two newtest_is_email_addresscases and onepartition_texttest. #957 addedEmailAddressto stop a bare address from becoming aTitle. A bare address still givesEmailAddress. BothEmailAddresselements intest_unstructured_ingest/expected-structured-outputstill passis_email_address(), so the fixtures stay the same.Verification
No issue exists for this, and no open pull request touches
is_email_address(). The CHANGELOG entry goes under0.27.34-dev2. The existing test keeps"[email protected]"atFalse, so a mixed-case address is still aTitle. This diff does not change that.With
fullmatch, any text after the address disqualifies it. Examples are a trailing period ([email protected].), a second address ([email protected], [email protected]) and a signature line such as[email protected] | +1 555 0100. Before, the prefix match made all three anEmailAddress. The strict check keeps the element from carrying text that is not the address. @cragwolfe, should trailing punctuation still count as anEmailAddress?