languagetool icon indicating copy to clipboard operation
languagetool copied to clipboard

[en] Comma before "whereas" grammar rule

Open OscarBrownbread opened this issue 1 year ago • 2 comments

Below is a grammar rule I created for English. A comma should be before "whereas".

Sources: Cambridge

Grammerist

MW

Note that there is no LT rule for when "Whereas" starts a sentence. That's why the below rule is case sensitive. I've also considered when "whereas" starts after a colon or semicolon, which can be correct.

                <!-- English rule, 2023-11-05 -->
		<rule id="COMMA_BEFORE_WHEREAS_MIDSENTENCE" name="Comma before whereas mid-sentence">	
			 <pattern case_sensitive='yes'>
			  <token regexp='yes' negate='yes'>[,;:]</token>
			  <token spacebefore='yes'>whereas</token>
			 </pattern>
			 <message>A comma precedes the conjunction <match no="2"/> mid-sentence to show contrast (except very short clauses). Also, check if you mean "although" instead.</message>
			 <url>https://dictionary.cambridge.org/grammar/british-grammar/whereas?q=Whereas</url>
			 <short>Comma before "whereas"</short>
			 <example correction=''>I go to <marker>London whereas</marker> you go to Paris.</example>
			 <example>I go to London, whereas you go to Paris.</example>
			 <suggestion>\1 , \2</suggestion>
		</rule>

OscarBrownbread avatar Nov 05 '23 14:11 OscarBrownbread

Hi @OscarBrownbread, thank you for contributing to LanguageTool!

This looks like a good rule, but I have a few small requests for changes:

  • please remove the unnecessary white space in the suggestion between \1 and ,, thus: \1, \2
  • please change the example correction to <example correction='London, whereas'>
  • please move the suggestion attribute above the url and below the message
  • please either modify the pattern or add an antipattern to avoid false positives in a sentence like As I mentioned it does repeal the whereas part, Sec 330.

Thank you again for contributing to LT!

evan-defran-lt avatar Nov 06 '23 08:11 evan-defran-lt

Hey @evan-defran-lt, thanks for the great suggestions. I've updated my code below. It's my first rule so that's my excuse for the sloppiness. :) I included a specific exception for "the" before "whereas", as suggested. I'm not sure of a better way, yet.

I had a look at the ngram again. I still consider the following to be grammatically wrong:

  1. conjunctions before whereas, e.g. "this is good, but whereas that is bad";
  2. en dash instead of a comma, e.g. this is good – whereas that is bad;
  3. comma inside quote, e.g. this is "good," whereas that is bad.

For the above three, the autocorrect suggestion doesn't fix them, but I think it's fine for now as the rule explains things.

Thanks!

		<rule id="COMMA_BEFORE_WHEREAS_MIDSENTENCE" name="Comma before whereas mid-sentence">	<!-- English rule, 2023-11-05 -->
			<antipattern>
				  <token>the</token>
				  <token>whereas</token>
				  <example>fix the whereas part</example>
			 </antipattern>
			 <pattern case_sensitive='yes'>
				<token regexp='yes' negate='yes'>[,;:]</token>
				<token spacebefore='yes'>whereas</token>
			 </pattern>
			 <message>A comma precedes the conjunction <match no="2"/> mid-sentence to show contrast (except very short clauses). Also, check if you mean "although" instead.</message>
			 <suggestion>\1, \2</suggestion>
			 <url>https://dictionary.cambridge.org/grammar/british-grammar/whereas?q=Whereas</url>
			 <short>Comma before "whereas" mid-sentence</short>
			 <example correction='London, whereas'>I go to <marker>London whereas</marker> you go to Paris.</example>
			 <example>I go to London, whereas you go to Paris.</example>
		</rule>

OscarBrownbread avatar Nov 06 '23 19:11 OscarBrownbread