Skip to content

⚡️Enhance segmentation regex patterns#197

Merged
HugoPerrier merged 7 commits into
masterfrom
feature/update_segmentation
Feb 26, 2026
Merged

⚡️Enhance segmentation regex patterns#197
HugoPerrier merged 7 commits into
masterfrom
feature/update_segmentation

Conversation

@HugoPerrier

Copy link
Copy Markdown
Contributor

Enhance segmentation and greetings detection in the melusine/processors.py module.
The segmentation regex construction is now "slighlty" more readable.

Improvements to segmentation logic:

  • Refactored the construction of segmentation regex patterns by distinguishing between mandatory and optional metadata keywords, introducing separate lists and corresponding patterns for each. This allows for more accurate extraction of headers like De, Cc, Copie, Attachments, Objet, etc.

Testing improvements:

  • Expanded test coverage for both segmentation and greetings detection;

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates email processing in melusine/processors.py by refining segmentation header detection (via regex construction) and expanding greetings detection, with additional tests to cover new/edge cases.

Changes:

  • Refactors segmentation regex construction by splitting header keywords into mandatory vs optional groups and rebuilding the meta-block matching logic.
  • Expands GREETINGS patterns to detect additional French closing formulas.
  • Adds/extends test cases for segmentation and greetings tagging behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
melusine/processors.py Refactors segmentation regex assembly and adds new greetings regex patterns.
tests/processors/test_processors.py Adds additional segmentation test cases covering tricky “false positive” and header formatting scenarios.
tests/processors/test_content_refined_tagger.py Extends greetings-related split/tag test cases to cover new closing formulas.
Comments suppressed due to low confidence (2)

melusine/processors.py:445

  • The comment says “Match everything until the end of the line”, but tolerant_line_start = r"^.{,5}" actually matches up to 5 characters at the start of a line (to tolerate prefixes like "> ", bullets, etc.). Please update the comment to reflect what the regex does so future edits don’t accidentally break the intended behavior.
        # Match everything until the end of the line.
        tolerant_line_start = r"^.{,5}"
        semicolon_pattern = r" ?\n? ?: *\n?"

tests/processors/test_processors.py:203

  • test_segmenter_2 duplicates the existing test_segmenter structure (same assertions/loop) and has a very generic docstring ("Test"). To keep the test suite maintainable, consider merging these new cases into the existing test_segmenter parametrization (or at least rename this test to a more specific name and use the standard docstring used elsewhere in this file).
def test_segmenter_2(input_text, expected_messages):
    """Test"""
    segmenter = Segmenter()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread melusine/processors.py Outdated
Comment thread melusine/processors.py
Comment thread melusine/processors.py Outdated
Comment thread tests/processors/test_processors.py Outdated
@HugoPerrier HugoPerrier merged commit df185df into master Feb 26, 2026
12 checks passed
@HugoPerrier HugoPerrier deleted the feature/update_segmentation branch February 26, 2026 15:57
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