4
0
(yes, that title was intentional)
Your task is to correct common grammatical mistakes.
You must:
- Capitalise the first letter of each sentence, ie the first non-whitespace letter after any of
.!?
and, additionally, capitalise the first letter of the input - Remove repeating punctuation, such as
!!! -> !
. Ellipses (...
) are not special, and will collapse into.
. - Remove repeating whitespace
<space><space><space> -> <space>
- Remove whitespace directly before any of
.,;!?
as in:Hello , World ! -> Hello, World!
- If there is no space directly after any of
.,;!?
, add it. - Add a
.
at the end of the input if there is not any of.!?
at the end. Not use Mathematica's builtins
Examples:
This is a sentence .Unfortunately, it's not very grammatically correct.can you fix it ???
This is a sentence. Unfortunately, it's not very grammatically correct. Can you fix it?
buffalo, buffalo;buffalo buffalo? Buffalo.buffalo Buffalo buffalo
Buffalo, buffalo; buffalo buffalo? Buffalo. Buffalo Buffalo buffalo.
i'm not sure what to put for this test case...
I'm not sure what to put for this test case.
!this is a test. .Can ...you . . . 'ear me Ground-Control? ?! 'ere as in what you do with you're [sic] ears !
! This is a test. Can. You. 'ear me Ground-Control?! 'ere as in what you do with you're [sic] ears!
"what about this?"
,"(or this.)"
? (I'm guessing"what about this? ".
and(or this. ).
, which is a shame, but golf be golf...) – Jonathan Allan – 2017-05-17T18:52:54.800What are all the possible characters that can appear in the input? – user41805 – 2017-05-17T18:53:20.867
Your last test case seems wrong, since nothing in the post says we need to remove repeated punctuation with whitespace inbetween. – James – 2017-05-17T19:57:31.153
would rules number 5 and 6 clash and end up having a trailing output of <space>.<space>.<space>.<space>.<space>. – tuskiomi – 2017-05-17T20:26:49.847
I like this challenge but I guess a better title might be "Correct peoples grammar according to the given rules". The rules are specific enough about what is required for me. If I am not misunderstanding, as long as the test cases are matched then the answer is valid. If my comment is grammatically incorrect then please feel free to use it as a further test case. – ElPedro – 2017-05-17T20:42:21.047
Do leading whitespace have to be removed? – user41805 – 2017-05-17T20:45:16.093
@KritixiLithos Not unless there is any of
.,;!?
after the whitespace at the start. – Okx – 2017-05-18T07:37:19.217