Improve get_sentences

This commit is contained in:
Andras Schmelczer 2022-06-26 12:08:19 +02:00
parent 75148b8954
commit 5319a46ff7
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
5 changed files with 77 additions and 21 deletions

View file

@ -11,6 +11,48 @@ class TestGetSentences(unittest.TestCase):
assert get_sentences(text) == expected
assert get_sentences(text, ignore_partial=True) == expected[0:2]
def test_complex(self) -> None:
text = """
This is a complete sentence. So is this.
End of paragraph.
Negation contractions (like don't or ain't) are resolved.
However this is not a sent
"""
expected = [
"This is a complete sentence.",
"So is this.",
"End of paragraph.",
"Negation contractions (like don't or ain't) are resolved.",
"However this is not a sent",
]
print(get_sentences(text, ignore_partial=True))
assert get_sentences(text) == expected
assert get_sentences(text, ignore_partial=True) == expected[:-1]
def test_true_casing(self) -> None:
text = "This is also referred to as a Convolutional Neural Network (CNN)."
expected = ["this is also referred to as a Convolutional Neural Network (CNN)."]
assert get_sentences(text, true_case=True) == expected
def test_remove_punctuation(self) -> None:
text = "Also, we --- the authors --- have to find less intrusive, and higher potential procedures. "
expected = [
"Also we the authors have to find less intrusive and higher potential procedures"
]
assert get_sentences(text, remove_punctuation=True) == expected
def test_empty(self) -> None:
assert get_sentences("") == []
assert get_sentences(" ") == []
assert get_sentences(" \n ") == []
assert get_sentences("", ignore_partial=True) == []
assert get_sentences("", true_case=True) == []
assert get_sentences("", remove_punctuation=True) == []