Class PatternRuleMatcher

java.lang.Object
org.languagetool.rules.patterns.AbstractPatternRulePerformer
org.languagetool.rules.patterns.PatternRuleMatcher
All Implemented Interfaces:
RuleMatcher

public final class PatternRuleMatcher extends AbstractPatternRulePerformer implements RuleMatcher
Matches a pattern rule against text.
  • Field Details

  • Constructor Details

    • PatternRuleMatcher

      PatternRuleMatcher(PatternRule rule, boolean useList)
  • Method Details

    • getCurrentRules

      public static Map<String,Integer> getCurrentRules()
    • match

      public RuleMatch[] match(AnalyzedSentence sentence) throws IOException
      Specified by:
      match in interface RuleMatcher
      Throws:
      IOException
    • createRuleMatch

      @Nullable private @Nullable RuleMatch createRuleMatch(List<Integer> tokenPositions, AnalyzedTokenReadings[] tokens, int firstMatchToken, int lastMatchToken, int firstMarkerMatchToken, int lastMarkerMatchToken, AnalyzedSentence sentence) throws IOException
      Throws:
      IOException
    • matchPreservesCase

      private boolean matchPreservesCase(List<Match> suggestionMatches, String msg)
      Checks if the suggestion starts with a match that is supposed to preserve case. If it does not, perform the default conversion to uppercase.
      Returns:
      true, if the match preserves the case of the token.
    • translateElementNo

      private int translateElementNo(int i)
      Gets the index of the element indexed by i, adding any offsets because of the phrases in the rule.
      Parameters:
      i - Current element index.
      Returns:
      int Index translated into XML element no.
    • formatMatches

      private String formatMatches(AnalyzedTokenReadings[] tokenReadings, List<Integer> positions, int firstMatchTok, String errorMsg, List<Match> suggestionMatches) throws IOException
      Replace back references generated with <match> and \\1 in message using Match class, and take care of skipping.
      Parameters:
      tokenReadings - Array of AnalyzedTokenReadings that were matched against the pattern
      positions - Array of relative positions of matched tokens
      firstMatchTok - Position of the first matched token
      errorMsg - String containing suggestion markup
      Returns:
      String Formatted message.
      Throws:
      IOException
    • concatWithoutExtraSpace

      private static String concatWithoutExtraSpace(String leftSide, String rightSide)
    • formatMultipleSynthesis

      static String formatMultipleSynthesis(String[] matches, String leftSide, String rightSide)
    • concatMatches

      private String[] concatMatches(int start, int index, int tokenIndex, AnalyzedTokenReadings[] tokens, int nextTokenPos, List<Match> suggestionMatches) throws IOException
      Concatenates the matches, and takes care of phrases (including inflection using synthesis).
      Parameters:
      start - Position of the element as referenced by match element in the rule.
      index - The index of the element found in the matching sentence.
      tokenIndex - The position of the token in the AnalyzedTokenReadings array.
      tokens - Array of AnalyzedTokenReadings
      Returns:
      Throws:
      IOException
    • phraseLen

      private int phraseLen(int i)
    • combineLists

      private static String[] combineLists(String[][] input, String[] output, int r, Language lang)
      Creates a Cartesian product of the arrays stored in the input array.
      Parameters:
      input - Array of string arrays to combine.
      output - Work array of strings.
      r - Starting parameter (use 0 to get all combinations).
      lang - Text language for adding spaces in some languages.
      Returns:
      Combined array of String.