Skip to content

Kravetsmic/787 email addresses shouldn't be flagged as titles - #957

Merged
MthwRobinson merged 31 commits into
Unstructured-IO:mainfrom
kravetsmic:kravetsmic/787_Email_addresses_shouldn't_be_flagged_as_titles
Aug 4, 2023
Merged

MthwRobinson merged 31 commits into
Unstructured-IO:mainfrom
kravetsmic:kravetsmic/787_Email_addresses_shouldn't_be_flagged_as_titles

Conversation

@kravetsmic

Copy link
Copy Markdown
Contributor

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

@MthwRobinson MthwRobinson 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.

The is_email_address implementation looks good, but could we not modify every example doc? I think a unit test should suffice here.

@kravetsmic

Copy link
Copy Markdown
Contributor Author

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?

@MthwRobinson

Copy link
Copy Markdown
Contributor

I don't think it needs a new test file, unit tests should be fine. Like the tests here.

@MthwRobinson MthwRobinson 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.

Added inline comments

Comment thread CHANGELOG.md Outdated

### Enhancements

* set the file's current position to the beginning after reading the file in `convert_to_bytes`

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.

Please take out these extra tabs that got added in the changelog

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.

Only change in this file should be the update to the version and the new changelog entry for the fix

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.

This and the next line still have the additional whitespace

Comment thread CHANGELOG.md Outdated
* 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

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.

You can remove this line

Comment thread CHANGELOG.md Outdated

### Features

* Adds new element type `EmailAddress` for recognising email address in the  text

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.

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(

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was because of my personal liner settings, I have changed them already, to what we have in the project

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.

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):

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.

What does this test for?

Comment thread unstructured/file_utils/filetype.py Outdated
)
if include_page_breaks and i < num_pages - 1:
page_elements.append(PageBreak(text=""))
print("page_element", page_elements)

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.

Remove this print statement

Comment thread CHANGELOG.md Outdated

### Features


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.

Can your remove this added new line?

@MthwRobinson MthwRobinson 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.

Can you add EmailAddress to the list of elements in the docs? PR's looking good otherwise pending a few formatting changes.

Comment thread CHANGELOG.md Outdated
* 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

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.

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

@MthwRobinson MthwRobinson 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.

LGTM - thanks!

@MthwRobinson
MthwRobinson merged commit bef93ae into Unstructured-IO:main Aug 4, 2023
jasonbot pushed a commit that referenced this pull request Aug 8, 2023
* 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]>
cragwolfe pushed a commit that referenced this pull request Oct 22, 2026
… 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]>
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.

2 participants