Remove trailing punctuation after standalone profanity with context-sensitive rules
:loudspeaker: The Shortcoming
I do not want to see periods or commas when the filter removes a specific word; otherwise, I would know that profanity was used. I do not want to know if there is profanity used, so periods and commas should be removed in some cases, while in other cases, they should be preserved.
:microscope: Describe the solution you'd like
I want to figure out how to remove a comma or period that appears immediately after a specific word, but only under certain conditions. I do not want to remove it in all cases, but only when the word appears standalone, without being part of a larger phrase.
For example:
-
Input:
Crap. What should I do? -
Desired Output:
What should I do?
In this case, the period after "Crap" is removed. However, I do not want this to happen if the word appears within a phrase before the punctuation.
For example:
-
Input:
Oh crap. What should I do? -
Desired Output:
Oh. What should I do?(The period remains unchanged.)
The same logic should also apply to commas. However, if the removed punctuation was followed by a lowercase word, that word should be capitalized unless it was already at the start of the sentence.
For example:
-
Input:
Crap, this is confusing. -
Desired Output:
This is confusing.(The comma is removed, and "this" is capitalized.) -
Input:
Oh crap, this is confusing. -
Desired Output:
Oh, this is confusing.(Since "crap" is part of a phrase, the comma is not removed.)
I want this logic to be applied effectively.
:triangular_ruler: Describe alternatives you've considered
I do not know of any solutions other than manually adding every single combination of periods and commas, along with profanity.
:pencil: Additional context
None.