Repository navigation
Kravetsmic/787 email addresses shouldn't be flagged as titles - #957
Conversation
…flagged_as_titles
MthwRobinson
left a comment
There was a problem hiding this comment.
The is_email_address implementation looks good, but could we not modify every example doc? I think a unit test should suffice here.
Do you mean to create new files for tests with an email address? |
|
I don't think it needs a new test file, unit tests should be fine. Like the tests here. |
MthwRobinson
left a comment
There was a problem hiding this comment.
Added inline comments
|
|
||
| ### Enhancements | ||
|
|
||
| * set the file's current position to the beginning after reading the file in `convert_to_bytes` |
There was a problem hiding this comment.
Please take out these extra tabs that got added in the changelog
There was a problem hiding this comment.
Only change in this file should be the update to the version and the new changelog entry for the fix
There was a problem hiding this comment.
This and the next line still have the additional whitespace
| * Removed old error message that's superseded by `requires_dependencies`. | ||
| * Removes using `hi_res` as the default strategy value for `partition_via_api` and `partition_multiple_via_api` | ||
|
|
||
| ## 0.8.2-dev3 |
There was a problem hiding this comment.
You can remove this line
|
|
||
| ### Features | ||
|
|
||
| * Adds new element type `EmailAddress` for recognising email address in the text |
There was a problem hiding this comment.
This should go under fixes
| document.add_paragraph("", style="Normal") | ||
| # NOTE(robinson) - this should get picked up as a narrative text | ||
| document.add_paragraph("This is my first thought. This is my second thought.", style="Normal") | ||
| document.add_paragraph( |
There was a problem hiding this comment.
Why do all of these test files have formatting changes? That should only occur if there's a version changing in the linters or something. Please revert these.
There was a problem hiding this comment.
It was because of my personal liner settings, I have changed them already, to what we have in the project
There was a problem hiding this comment.
Can you your lint/format again or revert this file to what it is currently on main?
| assert elements[0].metadata.filename is None | ||
|
|
||
|
|
||
| def test_partition_docx_from_file_wi(mock_document, tmpdir): |
There was a problem hiding this comment.
What does this test for?
| ) | ||
| if include_page_breaks and i < num_pages - 1: | ||
| page_elements.append(PageBreak(text="")) | ||
| print("page_element", page_elements) |
There was a problem hiding this comment.
Remove this print statement
|
|
||
| ### Features | ||
|
|
||
|
|
There was a problem hiding this comment.
Can your remove this added new line?
| * Removed old error message that's superseded by `requires_dependencies`. | ||
| * Removes using `hi_res` as the default strategy value for `partition_via_api` and `partition_multiple_via_api` | ||
|
|
||
| ### Enhancements |
There was a problem hiding this comment.
I thought these were whitespace changes, but these changelog entries might have been duplicated due to a merge conflict or something like that. Can you remove these (L114-L117) since they don't pertain to this PR? Only changelog update should be the version and the entry describing this PR
…flagged_as_titles
* feat: add func for checking on EmailAddress type * feat: add EmailAddress type * feat: add check for email type * feat: add test for cheking EmailAdress type * feat: update existing example files with email * feat: add new exampe fileds with email in the text * fix: apply linter * feat: update changelog file * feat: add test for is_email_address function * don't push * fix: clean up code * apply linter * fix: clean up * fix: remove file chaanges * fix: remove not used files for email address test * fix: remove not necessary tests * clean up * fix: apply linter * fix: update CHANGELOG * fix: change version * fix: fix msg test * fix: apply linter for tests * fix: remove spaces * fix: apply linter with longer line * feat: update documentation * fix: remove duplicates * Update getting_started.rst --------- Co-authored-by: Matt Robinson <[email protected]>
… is one (#4577) 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 calls `EMAIL_ADDRESS_PATTERN_RE.match`, so only the start of the text must be an address. `partition_text`, `partition_html`, `partition_docx` and `partition_pptx` all send text through this check. ``` # base 9a37644, probe builds each document from the same sentence: # "[email protected] is the address for every invoice question you have." $ python probe_email.py text ['EmailAddress'] html ['EmailAddress'] docx ['EmailAddress'] pptx ['EmailAddress'] ``` On this branch the same probe prints `['NarrativeText']` for all four. The change is `fullmatch` on the stripped text, with two new `test_is_email_address` cases and one `partition_text` test. #957 added `EmailAddress` to stop a bare address from becoming a `Title`. A bare address still gives `EmailAddress`. Both `EmailAddress` elements in `test_unstructured_ingest/expected-structured-output` still pass `is_email_address()`, so the fixtures stay the same. ### Verification ``` # base 9a37644, python 3.12, uv sync --frozen --group test --group lint --extra docx --extra pptx $ pytest test_unstructured/partition/test_text_type.py test_unstructured/partition/test_text.py test_unstructured/partition/html test_unstructured/partition/test_docx.py test_unstructured/partition/test_pptx.py -q -n 4 3 failed, 895 passed # base 3 failed, 898 passed # this branch # the 3 are the *_last_modified_from_filesystem tests, failing identically on both runs in an exported tree $ pytest test_unstructured/partition/test_text_type.py test_unstructured/partition/test_text.py -q # text_type.py reverted, tests kept 3 failed, 186 passed # both new test_is_email_address cases and the partition_text test $ ruff check . && ruff format --check . # ruff 0.15.10 All checks passed! 353 files already formatted $ make check-version version sync would make no changes to unstructured/__version__.py. ``` No issue exists for this, and no open pull request touches `is_email_address()`. The CHANGELOG entry goes under `0.27.34-dev2`. The existing test keeps `"[email protected]"` at `False`, so a mixed-case address is still a `Title`. 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 an `EmailAddress`. The strict check keeps the element from carrying text that is not the address. @cragwolfe, should trailing punctuation still count as an `EmailAddress`? <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4577?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: Christopher Krah <[email protected]>
Summary
Added new element type EmailAddress, so email address in the text no longer flagged as the Title
Bump to 0.8.3
Closes issue #787