public class Unifier extends Object
| Constructor and Description |
|---|
Unifier(Map<org.languagetool.rules.patterns.EquivalenceTypeLocator,PatternToken> equivalenceTypes,
Map<String,List<String>> equivalenceFeatures)
Instantiates the unifier.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNeutralElement(AnalyzedTokenReadings analyzedTokenReadings)
Used to add neutral elements (
AnalyzedTokenReadings to the
unified sequence. |
boolean |
getFinalUnificationValue(Map<String,List<String>> uFeatures)
Make sure that we really matched all the required features of the unification.
|
AnalyzedTokenReadings[] |
getFinalUnified()
Used for getting a unified sequence in case when simple test method
isUnified(AnalyzedToken, Map, boolean)} was used. |
AnalyzedTokenReadings[] |
getUnifiedTokens()
Gets a full sequence of filtered tokens.
|
protected boolean |
isSatisfied(AnalyzedToken aToken,
Map<String,List<String>> uFeatures)
Tests if a token has shared features with other tokens.
|
boolean |
isUnified(AnalyzedToken matchToken,
Map<String,List<String>> uFeatures,
boolean lastReading) |
boolean |
isUnified(AnalyzedToken matchToken,
Map<String,List<String>> uFeatures,
boolean lastReading,
boolean isMatched)
Tests if the token sequence is unified.
|
void |
reset()
Resets after use of unification.
|
void |
startNextToken()
Call after every complete token (AnalyzedTokenReadings) checked.
|
void |
startUnify()
Starts testing only those equivalences that were previously matched.
|
protected final boolean isSatisfied(AnalyzedToken aToken, Map<String,List<String>> uFeatures)
aToken - token to be testeduFeatures - features to be testedpublic final void startNextToken()
public final void startUnify()
public final boolean getFinalUnificationValue(Map<String,List<String>> uFeatures)
uFeatures - Features to be checkedpublic final void reset()
@Nullable public final AnalyzedTokenReadings[] getUnifiedTokens()
nullpublic final boolean isUnified(AnalyzedToken matchToken, Map<String,List<String>> uFeatures, boolean lastReading, boolean isMatched)
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 isUnified() for every reading of a token,
and set lastReading to true. For the last token, check the
truth value returned by this method. In previous cases, it may actually be
discarded before the final check. See AbstractPatternRule for
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 using PatternToken.setLastInUnification()).matchToken - AnalyzedToken token to unifylastReading - true when the matchToken is the last reading in the AnalyzedTokenReadingsisMatched - true if the reading matches the element in the pattern rule,
otherwise the reading is not considered in the unificationpublic final boolean isUnified(AnalyzedToken matchToken, Map<String,List<String>> uFeatures, boolean lastReading)
public final void addNeutralElement(AnalyzedTokenReadings analyzedTokenReadings)
AnalyzedTokenReadings to the
unified sequence. Useful if the sequence contains punctuation or connectives, for example.analyzedTokenReadings - A neutral element to be added.@Nullable public final AnalyzedTokenReadings[] getFinalUnified()
isUnified(AnalyzedToken, Map, boolean)} was used.AnalyzedTokenReadings or null when not in unification