Package org.languagetool.rules.patterns
Class Unifier
java.lang.Object
org.languagetool.rules.patterns.Unifier
Implements unification of features over tokens.
- Author:
- Marcin Milkowski
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddNeutralElement(AnalyzedTokenReadings analyzedTokenReadings) Used to add neutral elements (AnalyzedTokenReadingsto the unified sequence.final booleangetFinalUnificationValue(Map<String, List<String>> uFeatures) Make sure that we really matched all the required features of the unification.final @Nullable AnalyzedTokenReadings[]Used for getting a unified sequence in case when simple test methodisUnified(AnalyzedToken, Map, boolean)} was used.final @Nullable AnalyzedTokenReadings[]Gets a full sequence of filtered tokens.protected final booleanisSatisfied(AnalyzedToken aToken, Map<String, List<String>> uFeatures) Tests if a token has shared features with other tokens.final booleanfinal booleanisUnified(AnalyzedToken matchToken, Map<String, List<String>> uFeatures, boolean lastReading, boolean isMatched) Tests if the token sequence is unified.final voidreset()Resets after use of unification.final voidCall after every complete token (AnalyzedTokenReadings) checked.final voidStarts testing only those equivalences that were previously matched.
-
Constructor Details
-
Method Details
-
isSatisfied
Tests if a token has shared features with other tokens.- Parameters:
aToken- token to be testeduFeatures- features to be tested- Returns:
- true if the token shares this type of feature with other tokens
-
startNextToken
public final void startNextToken()Call after every complete token (AnalyzedTokenReadings) checked. -
startUnify
public final void startUnify()Starts testing only those equivalences that were previously matched. -
getFinalUnificationValue
Make sure that we really matched all the required features of the unification.- Parameters:
uFeatures- Features to be checked- Returns:
- True if the token sequence has been found.
- Since:
- 2.5
-
reset
public final void reset()Resets after use of unification. Required. -
getUnifiedTokens
Gets a full sequence of filtered tokens.- Returns:
- Array of AnalyzedTokenReadings that match equivalence relation
defined for features tested, or
null
-
isUnified
public final boolean isUnified(AnalyzedToken matchToken, Map<String, List<String>> uFeatures, boolean lastReading, boolean isMatched) Tests if the token sequence is unified.Usage note: to test if the sequence of tokens is unified (i.e., shares a group of features, such as the same gender, number, grammatical case etc.), you need to test all tokens but the last one in the following way: call
To make it work in XML rules, the Elements built based onisUnified()for every reading of a token, and setlastReadingtotrue. For the last token, check the truth value returned by this method. In previous cases, it may actually be discarded before the final check. SeeAbstractPatternRulefor an example.<token>s inside the unify block have to be processed in a special way: namely the last Element has to be marked as the last one (by usingPatternToken.setLastInUnification()).- Parameters:
matchToken-AnalyzedTokentoken to unifylastReading- true when the matchToken is the last reading in theAnalyzedTokenReadingsisMatched- true if the reading matches the element in the pattern rule, otherwise the reading is not considered in the unification- Returns:
- true if the tokens in the sequence are unified
-
isUnified
public final boolean isUnified(AnalyzedToken matchToken, Map<String, List<String>> uFeatures, boolean lastReading) -
addNeutralElement
Used to add neutral elements (AnalyzedTokenReadingsto the unified sequence. Useful if the sequence contains punctuation or connectives, for example.- Parameters:
analyzedTokenReadings- A neutral element to be added.- Since:
- 2.5
-
getFinalUnified
Used for getting a unified sequence in case when simple test methodisUnified(AnalyzedToken, Map, boolean)} was used.- Returns:
- An array of
AnalyzedTokenReadingsornullwhen not in unification
-