Package org.languagetool.rules.patterns
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 Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.Integer>
currentlyActiveRules
static java.lang.String
MISTAKE
private boolean
monitorRules
private java.util.List<PatternTokenMatcher>
patternTokenMatchers
private static java.lang.String
SUGGESTION_END_TAG
private static java.lang.String
SUGGESTION_START_TAG
private boolean
useList
-
Fields inherited from class org.languagetool.rules.patterns.AbstractPatternRulePerformer
prevMatched, rule, unifiedTokens, unifier
-
-
Constructor Summary
Constructors Constructor Description PatternRuleMatcher(PatternRule rule, boolean useList)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String[]
combineLists(java.lang.String[][] input, java.lang.String[] output, int r, Language lang)
Creates a Cartesian product of the arrays stored in the input array.private java.lang.String[]
concatMatches(int start, int index, int tokenIndex, AnalyzedTokenReadings[] tokens, int nextTokenPos, java.util.List<Match> suggestionMatches)
Concatenates the matches, and takes care of phrases (including inflection using synthesis).private static java.lang.String
concatWithoutExtraSpace(java.lang.String leftSide, java.lang.String rightSide)
private @Nullable RuleMatch
createRuleMatch(java.util.List<java.lang.Integer> tokenPositions, AnalyzedTokenReadings[] tokens, int firstMatchToken, int lastMatchToken, int firstMarkerMatchToken, int lastMarkerMatchToken, AnalyzedSentence sentence)
private java.lang.String
formatMatches(AnalyzedTokenReadings[] tokenReadings, java.util.List<java.lang.Integer> positions, int firstMatchTok, java.lang.String errorMsg, java.util.List<Match> suggestionMatches)
Replace back references generated with <match> and \\1 in message using Match class, and take care of skipping.(package private) static java.lang.String
formatMultipleSynthesis(java.lang.String[] matches, java.lang.String leftSide, java.lang.String rightSide)
static java.util.Map<java.lang.String,java.lang.Integer>
getCurrentRules()
RuleMatch[]
match(AnalyzedSentence sentence)
private boolean
matchPreservesCase(java.util.List<Match> suggestionMatches, java.lang.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 Detail
-
MISTAKE
public static final java.lang.String MISTAKE
- See Also:
- Constant Field Values
-
currentlyActiveRules
private static final java.util.Map<java.lang.String,java.lang.Integer> currentlyActiveRules
-
SUGGESTION_START_TAG
private static final java.lang.String SUGGESTION_START_TAG
- See Also:
- Constant Field Values
-
SUGGESTION_END_TAG
private static final java.lang.String SUGGESTION_END_TAG
- See Also:
- Constant Field Values
-
useList
private final boolean useList
-
patternTokenMatchers
private final java.util.List<PatternTokenMatcher> patternTokenMatchers
-
monitorRules
private final boolean monitorRules
-
-
Constructor Detail
-
PatternRuleMatcher
PatternRuleMatcher(PatternRule rule, boolean useList)
-
-
Method Detail
-
getCurrentRules
public static java.util.Map<java.lang.String,java.lang.Integer> getCurrentRules()
-
match
public RuleMatch[] match(AnalyzedSentence sentence) throws java.io.IOException
- Specified by:
match
in interfaceRuleMatcher
- Throws:
java.io.IOException
-
createRuleMatch
@Nullable private @Nullable RuleMatch createRuleMatch(java.util.List<java.lang.Integer> tokenPositions, AnalyzedTokenReadings[] tokens, int firstMatchToken, int lastMatchToken, int firstMarkerMatchToken, int lastMarkerMatchToken, AnalyzedSentence sentence) throws java.io.IOException
- Throws:
java.io.IOException
-
matchPreservesCase
private boolean matchPreservesCase(java.util.List<Match> suggestionMatches, java.lang.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 java.lang.String formatMatches(AnalyzedTokenReadings[] tokenReadings, java.util.List<java.lang.Integer> positions, int firstMatchTok, java.lang.String errorMsg, java.util.List<Match> suggestionMatches) throws java.io.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:
java.io.IOException
-
concatWithoutExtraSpace
private static java.lang.String concatWithoutExtraSpace(java.lang.String leftSide, java.lang.String rightSide)
-
formatMultipleSynthesis
static java.lang.String formatMultipleSynthesis(java.lang.String[] matches, java.lang.String leftSide, java.lang.String rightSide)
-
concatMatches
private java.lang.String[] concatMatches(int start, int index, int tokenIndex, AnalyzedTokenReadings[] tokens, int nextTokenPos, java.util.List<Match> suggestionMatches) throws java.io.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:
java.io.IOException
-
phraseLen
private int phraseLen(int i)
-
combineLists
private static java.lang.String[] combineLists(java.lang.String[][] input, java.lang.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.
-
-