Class GenericUnpairedBracketsRule

java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.TextLevelRule
org.languagetool.rules.GenericUnpairedBracketsRule

public class GenericUnpairedBracketsRule extends TextLevelRule
Rule that finds unpaired quotes, brackets etc.
  • Field Details

    • NUMERALS_EN

      private static final Pattern NUMERALS_EN
    • PUNCTUATION

      private static final Pattern PUNCTUATION
    • PUNCTUATION_NO_DOT

      private static final Pattern PUNCTUATION_NO_DOT
    • startSymbols

      private final List<String> startSymbols
    • endSymbols

      private final List<String> endSymbols
    • uniqueMap

      private final Map<String,Boolean> uniqueMap
    • ruleId

      private final String ruleId
    • numerals

      private final Pattern numerals
  • Constructor Details

    • GenericUnpairedBracketsRule

      public GenericUnpairedBracketsRule(String ruleId, ResourceBundle messages, List<String> startSymbols, List<String> endSymbols)
    • GenericUnpairedBracketsRule

      public GenericUnpairedBracketsRule(String ruleId, ResourceBundle messages, List<String> startSymbols, List<String> endSymbols, Pattern numerals)
      Since:
      3.7
    • GenericUnpairedBracketsRule

      public GenericUnpairedBracketsRule(ResourceBundle messages, List<String> startSymbols, List<String> endSymbols)
      Parameters:
      startSymbols - start symbols like "(" - note that the array must be of equal length as the next parameter and the sequence of starting symbols must match exactly the sequence of ending symbols.
      endSymbols - end symbols like ")"
    • GenericUnpairedBracketsRule

      public GenericUnpairedBracketsRule(ResourceBundle messages, List<String> startSymbols, List<String> endSymbols, Pattern numerals)
      Since:
      3.7
    • GenericUnpairedBracketsRule

      public GenericUnpairedBracketsRule(ResourceBundle messages)
      Construct rule with a set of default start and end symbols: [] () {} "" ''
  • Method Details

    • getId

      public String getId()
      Description copied from class: Rule
      A string used to identify the rule in e.g. configuration files. This string is supposed to be unique and to stay the same in all upcoming versions of LanguageTool. It's supposed to contain only the characters A-Z and the underscore.
      Specified by:
      getId in class Rule
    • 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
    • isNoException

      protected boolean isNoException(String token, AnalyzedTokenReadings[] tokens, int i, int j, boolean precSpace, boolean follSpace, UnsyncStack<SymbolLocator> symbolStack)
      Generic method to specify an exception. For unspecified language, it simply returns true (which means no exception) unless there's a common smiley like :-) or ;-).
      Parameters:
      token - String token
      tokens - Sentence tokens
      i - Current token index
      precSpace - is preceded with space
      follSpace - is followed with space
    • match

      public final RuleMatch[] match(List<AnalyzedSentence> sentences)
      Specified by:
      match in class TextLevelRule
    • uniqueMapInit

      private Map<String,Boolean> uniqueMapInit()
    • fillSymbolStack

      private boolean fillSymbolStack(int startPosBase, AnalyzedTokenReadings[] tokens, int i, int j, UnsyncStack<SymbolLocator> symbolStack, AnalyzedSentence sentence)
    • getPrecededByWhitespace

      private boolean getPrecededByWhitespace(AnalyzedTokenReadings[] tokens, int i, int j)
    • getFollowedByWhitespace

      private boolean getFollowedByWhitespace(AnalyzedTokenReadings[] tokens, int i, int j)
    • isEndSymbolUnique

      private boolean isEndSymbolUnique(String str)
    • createMatch

      @Nullable private @Nullable RuleMatch createMatch(List<RuleMatch> ruleMatches, UnsyncStack<SymbolLocator> ruleMatchStack, int startPos, String symbol, AnalyzedSentence sentence, List<AnalyzedSentence> sentences)
    • findCorrespondingSymbol

      private String findCorrespondingSymbol(String symbol)
    • 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