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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.languagetool.rules.patterns.AbstractPatternRulePerformer
AbstractPatternRulePerformer.MatchConsumer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringstatic final Stringprivate static final booleanprivate static final Patternprivate static final Patternprivate final booleanprivate static final PatternFields 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 StringconcatWithoutExtraSpace(String leftSide, String rightSide) private RuleMatchcreateRuleMatch(int[] tokenPositions, AnalyzedTokenReadings[] tokens, int firstMatchToken, int lastMatchToken, int firstMarkerMatchToken, int lastMarkerMatchToken, AnalyzedSentence sentence) private StringformatMatches(AnalyzedTokenReadings[] tokenReadings, int[] 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 StringformatMultipleSynthesis(String[] matches, String leftSide, String rightSide) match(AnalyzedSentence sentence) private booleanmatchPreservesCase(List<Match> suggestionMatches, String msg) Checks if the suggestion starts with a match that is supposed to preserve case.private intphraseLen(int i) private static Stringprotected booleantestAllReadings(AnalyzedTokenReadings[] tokens, PatternTokenMatcher matcher, PatternTokenMatcher prevElement, int tokenNo, int firstMatchToken, int prevSkipNext) (package private) inttranslateElementNo(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
doMatch, isInterpretPosTagsPreDisambiguation
-
Field Details
-
MISTAKE
- See Also:
-
currentlyActiveRules
-
allowedChars
- See Also:
-
SUGGESTION_PATTERN_SUPPRESS
-
WHITESPACE_OR_PUNCT
-
TAG_AND_PLEASE_SPELL_ME
-
useList
private final boolean useList -
monitorRules
private static final boolean monitorRules
-
-
Constructor Details
-
PatternRuleMatcher
-
-
Method Details
-
getCurrentRules
-
match
- Specified by:
matchin interfaceRuleMatcher- Throws:
IOException
-
testAllReadings
protected boolean testAllReadings(AnalyzedTokenReadings[] tokens, PatternTokenMatcher matcher, PatternTokenMatcher prevElement, int tokenNo, int firstMatchToken, int prevSkipNext) throws IOException - Overrides:
testAllReadingsin classAbstractPatternRulePerformer- Throws:
IOException
-
createRuleMatch
@Nullable private RuleMatch createRuleMatch(int[] 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
int translateElementNo(int i) Gets the index of the element indexed by i, adding any offsets because of the phrases in the rule.- Overrides:
translateElementNoin classAbstractPatternRulePerformer- Parameters:
i- Current element index.- Returns:
- int Index translated into XML element no.
-
formatMatches
private String formatMatches(AnalyzedTokenReadings[] tokenReadings, int[] 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
-
removeSuppressMisspelled
-
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.
-