Class AbstractStatisticSentenceStyleRule

java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.TextLevelRule
org.languagetool.rules.AbstractStatisticSentenceStyleRule
Direct Known Subclasses:
ConjunctionAtBeginOfSentenceRule, PassiveSentenceRule, SentenceWithManRule, SentenceWithModalVerbRule

public abstract class AbstractStatisticSentenceStyleRule extends TextLevelRule
A rule that gives hints when a defined condition is fulfilled and the percentage of hints in the text exceeds the given limit. (For office extension: Works on the level of chapters) A limit of 0 shows all hints. Direct speech or citation can be excluded. A second condition per sentences can be defined. The rule detects no grammar error but gives stylistic hints in a statistic way (default off).
Since:
5.3
  • Field Details

    • OPENING_QUOTES

      private static final Pattern OPENING_QUOTES
    • ENDING_QUOTES

      private static final Pattern ENDING_QUOTES
    • MARKS_REGEX

      private static final Pattern MARKS_REGEX
    • DEFAULT_ACTIVATION

      private static final boolean DEFAULT_ACTIVATION
      See Also:
    • minPercent

      private final int minPercent
    • defaultMinPercent

      private final int defaultMinPercent
    • sentenceCount

      private int sentenceCount
    • numMatches

      private int numMatches
    • withoutDirectSpeech

      private boolean withoutDirectSpeech
  • Constructor Details

    • AbstractStatisticSentenceStyleRule

      public AbstractStatisticSentenceStyleRule(ResourceBundle messages, Language lang, UserConfig userConfig, int minPercent, boolean defaultActive)
    • AbstractStatisticSentenceStyleRule

      public AbstractStatisticSentenceStyleRule(ResourceBundle messages, Language lang, UserConfig userConfig, int minPercent)
  • Method Details

    • conditionFulfilled

      protected abstract AnalyzedTokenReadings conditionFulfilled(List<AnalyzedTokenReadings> tokens)
      Condition to generate a hint (possibly including all exceptions) Returns: < nAnalysedToken, if condition is not fulfilled >= nAnalysedToken, if condition is not fulfilled; integer is number of token which is the end hint
    • excludeDirectSpeech

      protected abstract boolean excludeDirectSpeech()
      Condition to generate a hint related to the sentence (possibly including all exceptions)
    • getLimitMessage

      protected abstract String getLimitMessage(int limit, double percent)
      Defines the message for hints which exceed the limit
    • getConfigureText

      public abstract String getConfigureText()
    • getMinPercent

      private int getMinPercent(UserConfig userConfig, int minPercentDefault)
    • isMark

      protected boolean isMark(AnalyzedTokenReadings token)
    • isOpeningQuote

      protected boolean isOpeningQuote(AnalyzedTokenReadings token)
    • denominator

      public double denominator()
      Override, if value should be given in an other unity than percent
    • getRuleOptions

      public RuleOption[] getRuleOptions()
      give the user the possibility to configure the function
      Overrides:
      getRuleOptions in class Rule
    • getSentenceCount

      public int getSentenceCount()
    • getNumberOfMatches

      public int getNumberOfMatches()
    • setWithoutDirectSpeech

      public void setWithoutDirectSpeech(boolean withoutDirectSpeech)
    • match

      public RuleMatch[] match(List<AnalyzedSentence> sentences) throws IOException
      Specified by:
      match in class TextLevelRule
      Throws:
      IOException
    • minToCheckParagraph

      public int minToCheckParagraph()
      Description copied from class: TextLevelRule
      Gives back the minimum number of paragraphs to check to give back a correct result. Only used by LO office extension.
      • n == -1 --> need to check full text (use only if really needed / bad performance) examples: AbstractWordCoherencyRule, GenericUnpairedBracketsRule, ...
      • n == 0 --> need only to check the current paragraph examples: MultipleWhitespaceRule, LongParagraphRule, ...
      • n >= 1 --> need only to check n paragraphs around the current paragraph examples: ParagraphRepeatBeginningRule (n == 1), WordRepeatBeginningRule (n == 2), ...
      Specified by:
      minToCheckParagraph in class TextLevelRule