Skip to content

Commit

Permalink
Merge pull request textstat#177 from LKirst/handleapostrophes
Browse files Browse the repository at this point in the history
Keep apostrophe even if contraction is at the end of a string
  • Loading branch information
alxwrd authored Aug 30, 2021
2 parents b8343f7 + d807f2d commit 1693bf0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .codespellignorelines
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sure youre really just removing the characters you want to remove
sure youre really just removing the characters you want to remove Didnt
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
I said: 'This is a test sentence to test the remove_punctuation function.
It's short and not the work of a singer-songwriter. But it'll suffice.'
Your answer was: "I don't know. If I were you I'd write a test; just to make
sure, you're really just removing the characters you want to remove!"
sure, you're really just removing the characters you want to remove!" Didn't
"""

punct_text_result_w_apostr = """
I said This is a test sentence to test the remove_punctuation function
It's short and not the work of a singersongwriter But it'll suffice
Your answer was I don't know If I were you I'd write a test just to make
sure you're really just removing the characters you want to remove
sure you're really just removing the characters you want to remove Didn't
"""

punct_text_result_wo_apostr = """
I said This is a test sentence to test the remove_punctuation function
Its short and not the work of a singersongwriter But itll suffice
Your answer was I dont know If I were you Id write a test just to make
sure youre really just removing the characters you want to remove
sure youre really just removing the characters you want to remove Didnt
"""

long_test = (
Expand Down
2 changes: 1 addition & 1 deletion textstat/textstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def remove_punctuation(self, text):
else:
# replace single quotation marks with double quotation marks but
# keep apostrophes in contractions
text = re.sub(r"\'(?!t\W|s\W|ve\W|ll\W|re\W|d\W)", '"', text)
text = re.sub(r"\'(?![tsd]\b|ve\b|ll\b|re\b)", '"', text)
# remove all punctuation except apostrophes
punctuation_regex = r"[^\w\s\']"

Expand Down

0 comments on commit 1693bf0

Please sign in to comment.