-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve handling of leading punctuation removal (#10761)
- Loading branch information
Showing
5 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import re | ||
|
||
|
||
def remove_leading_symbols(text: str) -> str: | ||
""" | ||
Remove leading punctuation or symbols from the given text. | ||
Args: | ||
text (str): The input text to process. | ||
Returns: | ||
str: The text with leading punctuation or symbols removed. | ||
""" | ||
# Match Unicode ranges for punctuation and symbols | ||
pattern = r"^[\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F!\"#$%&'()*+,\-./:;<=>?@\[\]^_`{|}~]+" | ||
return re.sub(pattern, "", text) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
from core.tools.utils.text_processing_utils import remove_leading_symbols | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("input_text", "expected_output"), | ||
[ | ||
("...Hello, World!", "Hello, World!"), | ||
("。测试中文标点", "测试中文标点"), | ||
("!@#Test symbols", "Test symbols"), | ||
("Hello, World!", "Hello, World!"), | ||
("", ""), | ||
(" ", " "), | ||
], | ||
) | ||
def test_remove_leading_symbols(input_text, expected_output): | ||
assert remove_leading_symbols(input_text) == expected_output |