Package org.languagetool.rules.patterns
Class PatternRuleMatcher
java.lang.Object
org.languagetool.rules.patterns.AbstractPatternRulePerformer
org.languagetool.rules.patterns.PatternRuleMatcher
- All Implemented Interfaces:
RuleMatcher
Matches a pattern rule against text.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
private final boolean
private final List
<PatternTokenMatcher> private static final String
private static final String
private final boolean
Fields inherited from class org.languagetool.rules.patterns.AbstractPatternRulePerformer
prevMatched, rule, unifiedTokens, unifier
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String[]
combineLists
(String[][] input, String[] output, int r, Language lang) Creates a Cartesian product of the arrays stored in the input array.private String[]
concatMatches
(int start, int index, int tokenIndex, AnalyzedTokenReadings[] tokens, int nextTokenPos, List<Match> suggestionMatches) Concatenates the matches, and takes care of phrases (including inflection using synthesis).private static String
concatWithoutExtraSpace
(String leftSide, String rightSide) private @Nullable RuleMatch
createRuleMatch
(List<Integer> tokenPositions, AnalyzedTokenReadings[] tokens, int firstMatchToken, int lastMatchToken, int firstMarkerMatchToken, int lastMarkerMatchToken, AnalyzedSentence sentence) private String
formatMatches
(AnalyzedTokenReadings[] tokenReadings, List<Integer> positions, int firstMatchTok, String errorMsg, List<Match> suggestionMatches) Replace back references generated with <match> and \\1 in message using Match class, and take care of skipping.(package private) static String
formatMultipleSynthesis
(String[] matches, String leftSide, String rightSide) match
(AnalyzedSentence sentence) private boolean
matchPreservesCase
(List<Match> suggestionMatches, String msg) Checks if the suggestion starts with a match that is supposed to preserve case.private int
phraseLen
(int i) private int
translateElementNo
(int i) Gets the index of the element indexed by i, adding any offsets because of the phrases in the rule.Methods inherited from class org.languagetool.rules.patterns.AbstractPatternRulePerformer
createElementMatchers, getMinOccurrenceCorrection, skipMaxTokens, testAllReadings, testUnificationAndGroups
-
Field Details
-
MISTAKE
- See Also:
-
currentlyActiveRules
-
SUGGESTION_START_TAG
- See Also:
-
SUGGESTION_END_TAG
- See Also:
-
useList
private final boolean useList -
patternTokenMatchers
-
monitorRules
private final boolean monitorRules
-
-
Constructor Details
-
PatternRuleMatcher
PatternRuleMatcher(PatternRule rule, boolean useList)
-
-
Method Details
-
getCurrentRules
-
match
- Specified by:
match
in interfaceRuleMatcher
- 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
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 patternpositions
- Array of relative positions of matched tokensfirstMatchTok
- Position of the first matched tokenerrorMsg
- String containing suggestion markup- Returns:
- String Formatted message.
- Throws:
IOException
-
concatWithoutExtraSpace
-
formatMultipleSynthesis
-
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:
- @String[] Array of concatenated strings
- Throws:
IOException
-
phraseLen
private int phraseLen(int i) -
combineLists
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.
-