Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore separator symbols #3404

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flair/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,11 @@ def __remove_zero_width_characters(text: str) -> str:
text = text.replace("\u200b", "")
text = text.replace("\ufe0f", "")
text = text.replace("\ufeff", "")

text = text.replace(
"\u2028", ""
) # LINE SEPARATOR & PARAGRAPH SEPARATOR are usually used for wrapping & displaying texts,
text = text.replace("\u2029", "") # but not for semantic meaning -> ignore them.
return text

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tokenize_sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,5 +485,12 @@ def test_token_positions_when_creating_word_by_word():
assert sentence.tokens[2].end_position == 13


def test_line_separator_is_ignored():
with_separator = "Untersuchungs-\u2028ausschüsse"
without_separator = "Untersuchungs-ausschüsse"

assert Sentence(with_separator).to_original_text() == Sentence(without_separator).to_original_text()


def no_op_tokenizer(text: str) -> List[str]:
return [text]
Loading