Class AbstractStyleRepeatedWordRule

java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.TextLevelRule
org.languagetool.rules.AbstractStyleRepeatedWordRule
Direct Known Subclasses:
GermanStyleRepeatedWordRule

public abstract class AbstractStyleRepeatedWordRule extends TextLevelRule
An abstract rule checks the appearance of same words in a sentence or in two consecutive sentences. The isTokenToCheck method can be used to check only specific words (e.g. substantive, verbs and adjectives). This rule detects no grammar error but a stylistic problem (default off)
Since:
4.1
  • Field Details

    • OPENING_QUOTES

      private static final Pattern OPENING_QUOTES
    • ENDING_QUOTES

      private static final Pattern ENDING_QUOTES
    • SINGLE_QUOTES

      private static final Pattern SINGLE_QUOTES
    • MAX_TOKEN_TO_CHECK

      private static final int MAX_TOKEN_TO_CHECK
      See Also:
    • MAX_DISTANCE_OF_SENTENCES

      private static final int MAX_DISTANCE_OF_SENTENCES
      See Also:
    • EXCLUDE_DIRECT_SPEECH

      private static final boolean EXCLUDE_DIRECT_SPEECH
      See Also:
    • linguServices

      protected final LinguServices linguServices
    • lang

      protected final Language lang
    • maxDistanceOfSentences

      protected int maxDistanceOfSentences
    • excludeDirectSpeech

      protected boolean excludeDirectSpeech
  • Constructor Details

  • Method Details

    • getId

      public String getId()
      Override this ID by adding a language acronym (e.g. STYLE_REPEATED_WORD_RULE_DE) to use adjustment of maxWords by option panel
      Specified by:
      getId in class Rule
      Since:
      4.1
    • getDescription

      public String getDescription()
      Description copied from class: Rule
      A short description of the error this rule can detect, usually in the language of the text that is checked.
      Specified by:
      getDescription in class Rule
    • messageSameSentence

      protected abstract String messageSameSentence()
    • messageSentenceBefore

      protected abstract String messageSentenceBefore()
    • messageSentenceAfter

      protected abstract String messageSentenceAfter()
    • getRuleOptions

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

      protected abstract boolean isTokenToCheck(AnalyzedTokenReadings token)
    • isTokenPair

      protected abstract boolean isTokenPair(AnalyzedTokenReadings[] tokens, int n, boolean before)
    • hasBreakToken

      private static boolean hasBreakToken(AnalyzedTokenReadings[] tokens)
    • isQuestionResponse

      private static boolean isQuestionResponse(int nAct, int nTest, List<AnalyzedTokenReadings[]> tokenList)
    • isTokenInSentence

      private boolean isTokenInSentence(AnalyzedTokenReadings testToken, AnalyzedTokenReadings[] tokens, boolean isDirectSpeech)
    • isPartOfWord

      protected boolean isPartOfWord(String testTokenText, String tokenText)
    • isExceptionPair

      protected boolean isExceptionPair(AnalyzedTokenReadings token1, AnalyzedTokenReadings token2)
    • setURL

      protected URL setURL(AnalyzedTokenReadings token) throws MalformedURLException
      Throws:
      MalformedURLException
    • isTokenInSentence

      private boolean isTokenInSentence(AnalyzedTokenReadings testToken, AnalyzedTokenReadings[] tokens, int notCheck, boolean isDirectSpeech)
    • isInQuotes

      private boolean isInQuotes(AnalyzedTokenReadings[] tokens, int i)
    • getStartsWithDirectSpeech

      private boolean getStartsWithDirectSpeech(int n, List<AnalyzedSentence> sentences, boolean isDirectSpeech)
    • 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