Back to LanguageTool Homepage - Privacy - Imprint

LongSentenceRule active by default


(Tiago F. Santos) #1

I would like to ask opinion about, setting this rule as on by default. This is a key rule for a style checker, and many users do not even know about it.
I am aware that it is too intrusive since it underlines too many words.
With the feature that Jaume introduced recently, getPriorityForId, we could set it as the lowest priority for all languages. This way, only 'perfect sentences' receive the warning, in case they need to.
If there is nothing against it, I would like to change the default, and add the priority definition to all affected languages.


(Daniel Naber) #2

There's currently no way for the user to set the limit. So we'd need to find a value that makes sense (I'm not sure if the current value does). For that, I think we should at least run some tests to get a feeling for what kind of sentences the rule will complain about.

Making the value configurable isn't as easy, at least when done properly. It would need to be supported not just for the stand-alone UI but also for the API and add-ons.


(Tiago F. Santos) #3

Right now, this rule is not visible to the user, special if they use the web page or browser add-ons. On those cases it is not even accessible.

I agree that the ideal way, would be to allow in the options a field for setting the number. But that would require too much work.

For server/commandline API, the class already can be defined in a per language bases. Everyone is using the default value (40 words), although the "users" requiring a change to it, would have to recompile.
The function can be called as LongSentenceRule(messages, >40) for more verbose languages.

It is easier to ignore a rule than to activate it, only one ‘ignore all’ to revert the behavior, and it is the same work, to enable a rule as it is to disable it, so there would be no extra clicks.

That extra clicks would only be needed if it ever becomes obnoxious. To prevent that the rule could be set to 45 or 50 words instead of current 40. I would prefer 50, but that is just a preference.

With the lowest priority, I doubt that bad writers would notice the difference and good writers would rarely see the warning anyway.

Alternatively, a 3rd entry variable could be added to the class. That way, each language mantainer could choose the default behavior of that rule.


(Tiago F. Santos) #4

The solution with the extra variable is done. Changed the Category from MISC to STYLE and activated for Portuguese only:

 .../org/languagetool/rules/LongSentenceRule.java   | 25 ++++++++++++++++------
 .../java/org/languagetool/language/Portuguese.java |  2 +-
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/languagetool-core/src/main/java/org/languagetool/rules/LongSentenceRule.java b/languagetool-core/src/main/java/org/languagetool/rules/LongSentenceRule.java
index 060797f..5fd85f2 100644
--- a/languagetool-core/src/main/java/org/languagetool/rules/LongSentenceRule.java
+++ b/languagetool-core/src/main/java/org/languagetool/rules/LongSentenceRule.java
@@ -35,29 +35,40 @@ public class LongSentenceRule extends Rule {
 
   private static final int DEFAULT_MAX_WORDS = 40;
   private static final Pattern NON_WORD_REGEX = Pattern.compile("[.?!:;,~’'\"„“»«‚‘›‹()\\[\\]-]");
+  private static final boolean DEFAULT_ACTIVE = false;
 
   private final int maxWords;
 
   /**
-   * @param maxSentenceLength the maximum sentence length that does not yet trigger a match
-   * @since 2.4
+   * @param defaultActive allows default granularity
+   * @since 3.7
*/
-  public LongSentenceRule(ResourceBundle messages, int maxSentenceLength) {
+  public LongSentenceRule(ResourceBundle messages, int maxSentenceLength, boolean defaultActive) {
 super(messages);
-    super.setCategory(Categories.MISC.getCategory(messages));
+    super.setCategory(Categories.STYLE.getCategory(messages));
 if (maxSentenceLength <= 0) {
   throw new IllegalArgumentException("maxSentenceLength must be > 0: " + maxSentenceLength);
 }
 maxWords = maxSentenceLength;
-    setDefaultOff();
+    if (!defaultActive) {
+      setDefaultOff();
+    }
 setLocQualityIssueType(ITSIssueType.Style);
   }
 
   /**
+   * @param maxSentenceLength the maximum sentence length that does not yet trigger a match
+   * @since 2.4
+   */
+  public LongSentenceRule(ResourceBundle messages, int maxSentenceLength) {
+    this(messages, maxSentenceLength, DEFAULT_ACTIVE);
+  }
+
+  /**
* Creates a rule with the default maximum sentence length (40 words).
*/
   public LongSentenceRule(ResourceBundle messages) {
-    this(messages, DEFAULT_MAX_WORDS);
+    this(messages, DEFAULT_MAX_WORDS, DEFAULT_ACTIVE);
   }
 
   @Override
@@ -100,4 +111,4 @@ public class LongSentenceRule extends Rule {
 // nothing here
   }
 
-}
\ No newline at end of file
+}
diff --git a/languagetool-language-modules/pt/src/main/java/org/languagetool/language/Portuguese.java b/languagetool-language-modules/pt/src/main/java/org/languagetool/language/Portuguese.java
index 98d9b7c..4effecb 100644
--- a/languagetool-language-modules/pt/src/main/java/org/languagetool/language/Portuguese.java
+++ b/languagetool-language-modules/pt/src/main/java/org/languagetool/language/Portuguese.java
@@ -139,7 +139,7 @@ public class Portuguese extends Language implements AutoCloseable {
             Example.fixed("Tomamos café<marker>,</marker> queijo, bolachas e uvas")),
         new GenericUnpairedBracketsRule(messages),
         new HunspellRule(messages, this),
-            new LongSentenceRule(messages),
+            new LongSentenceRule(messages, 45, true),
         new UppercaseSentenceStartRule(messages, this,
             Example.wrong("Esta casa é velha. <marker>foi</marker> construida em 1950."),
             Example.fixed("Esta casa é velha. <marker>Foi</marker> construida em 1950.")),

Can I push it?


(Daniel Naber) #5

Looks good!


(Tiago F. Santos) #6

Many thanks! Pushed to master.