Skip to content

fix(general_text): stop RemoveImageRefsRefiner from deleting long words - #569

Open
raams95 wants to merge 1 commit into
OpenDCAI:mainfrom
raams95:fix/remove-image-refs-keeps-long-words
Open

raams95 wants to merge 1 commit into
OpenDCAI:mainfrom
raams95:fix/remove-image-refs-keeps-long-words

Conversation

@raams95

@raams95 raams95 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

One alternative in RemoveImageRefsRefiner's pattern, (?:[0-9a-zA-Z]+){7,}, matches any run of 7 or more ASCII letters or digits. Because of that, the refiner removed every ordinary word of that length, even in rows with no image reference:

"Machine learning algorithms are powerful."  ->  "   are ."
"Information retrieval matters"              ->  "  "
"Visit https://example.com today"            ->  "Visit https://.com today"

Fix

Remove that alternative. The rest of the pattern is unchanged, and it still strips the Markdown image links (![](images/a.jpg), ![](images/<hex>.jpg)), hashed file-name tails and 图 1-2:... captions.

Tests

I added test/cpu_only/test_remove_image_refs_refiner.py:

  • test_words_of_seven_or_more_characters_are_kept: plain English sentences come back unchanged

  • test_image_references_are_still_removed: a short image link, a hashed image link and a 图 x-y: caption are still removed

  • Before the fix: 1 failed (long words removed), 1 passed

  • After the fix: 2 passed

pytest -m "cpu or api" test/cpu_only/test_remove_image_refs_refiner.py -q
2 passed

Fixes #568

One alternative in the image-reference pattern, (?:[0-9a-zA-Z]+){7,},
matches any run of seven or more ASCII letters or digits, so every
ordinary word of that length was removed: "Machine learning algorithms
are powerful." became "   are .". Drop it; the remaining alternatives
still strip the Markdown image links and hashed image file names.

Fixes OpenDCAI#568

This branch has not been deployed

No deployments
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.

RemoveImageRefsRefiner deletes every word of 7 or more letters

1 participant