Package org.predict4all.nlp.words.model
Class AbstractWord
- java.lang.Object
-
- org.predict4all.nlp.words.model.AbstractWord
-
- All Implemented Interfaces:
Word
- Direct Known Subclasses:
EquivalenceClassWord
,SimpleWord
,TagWord
public abstract class AbstractWord extends Object implements Word
-
-
Field Summary
-
Fields inherited from interface org.predict4all.nlp.words.model.Word
TYPE_EQUIVALENCE_CLASS, TYPE_NGRAM_TAG, TYPE_SIMPLE, TYPE_USER_WORD
-
-
Constructor Summary
Constructors Constructor Description AbstractWord(int id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EquivalenceClass
getEquivalenceClass()
byte
getEquivalenceClassId()
int
getID()
long
getLastUseDate()
Tag
getNGramTag()
byte
getNGramTagId()
double
getProbFactor()
This factor can be used to modify final probabilities of the predictions.
It will be applied once probabilities are computed to influence result list.
It is mainly used in a multiplication with the original probability (and then the result list is normalized).
To only rely on probabilities, the value should be 1.0int
getUsageCount()
void
incrementUsageCount()
To increase the "usage" count of this wordboolean
isEquivalenceClass()
boolean
isForceInvalid()
To force that this word is invalid.
In fact, this method allow removal of a word from prediction result : words can't be removed from dictionary as they can be used in ngrams, but having forceInvalid true has the same effect than removing a word.boolean
isForceValid()
To force that this word become valid, mostly use onUserWord
to ignore validation.boolean
isModifiedBySystem()
Indicate that this word was modified by the system (e.g. calling a modification method withmodificationByUser
parameter to false)boolean
isModifiedByUser()
Indicate that this word was modified by the user (e.g. calling a modification method withmodificationByUser
parameter to true)boolean
isModifiedByUserOrSystem()
boolean
isNGramTag()
boolean
isUserWord()
boolean
isValidForSaving()
boolean
isValidToBePredicted(PredictionParameter predictionParameter)
To check if this word can be displayed as a prediction result.
This typically return true for original words, but can be sensible to computation for user words.
This can also return true/false regardingWord.isForceInvalid()
orWord.isForceValid()
Also, user word are valid for prediction regardingPredictionParameter.getMinUseCountToValidateNewWord()
void
setForceInvalid(boolean forceInvalid, boolean modificationByUser)
To force that this word is invalid.
In fact, this method allow removal of a word from prediction result : words can't be removed from dictionary as they can be used in ngrams, but having forceInvalid true has the same effect than removing a word.void
setForceValid(boolean forceValid, boolean modificationByUser)
To force that this word become valid, mostly use onUserWord
to ignore validation.void
setModifiedBySystem(boolean modifiedBySystem)
To manually set modification by system flagvoid
setModifiedByUser(boolean modified)
To manually set modification by user flagvoid
setProbFactor(double factor, boolean modificationByUser)
This factor can be used to modify final probabilities of the predictions.
It will be applied once probabilities are computed to influence result list.
It is mainly used in a multiplication with the original probability (and then the result list is normalized).
To only rely on probabilities, the value should be 1.0String
toString()
-
-
-
Method Detail
-
getID
public int getID()
-
getEquivalenceClass
public EquivalenceClass getEquivalenceClass()
- Specified by:
getEquivalenceClass
in interfaceWord
- Returns:
- the equivalence class represented by this word (only if
Word.isEquivalenceClass()
)
-
isEquivalenceClass
public boolean isEquivalenceClass()
- Specified by:
isEquivalenceClass
in interfaceWord
- Returns:
- true if this word is
EquivalenceClassWord
instance
-
getEquivalenceClassId
public byte getEquivalenceClassId()
- Specified by:
getEquivalenceClassId
in interfaceWord
- Returns:
- the equivalence class id represented by this word (only if
Word.isEquivalenceClass()
)
-
isNGramTag
public boolean isNGramTag()
- Specified by:
isNGramTag
in interfaceWord
- Returns:
- true if this word is
TagWord
instance
-
getNGramTagId
public byte getNGramTagId()
- Specified by:
getNGramTagId
in interfaceWord
- Returns:
- the ngram tag id represented by this word (only if
Word.isNGramTag()
)
-
getNGramTag
public Tag getNGramTag()
- Specified by:
getNGramTag
in interfaceWord
- Returns:
- the ngram tag represented by this word (only if
Word.isNGramTag()
)
-
isUserWord
public boolean isUserWord()
- Specified by:
isUserWord
in interfaceWord
- Returns:
- true if this word is
UserWord
instance
-
isValidForSaving
public boolean isValidForSaving()
- Specified by:
isValidForSaving
in interfaceWord
- Returns:
- true if this world should be saved (in both original and user dictionary)
-
isValidToBePredicted
public boolean isValidToBePredicted(PredictionParameter predictionParameter)
Description copied from interface:Word
To check if this word can be displayed as a prediction result.
This typically return true for original words, but can be sensible to computation for user words.
This can also return true/false regardingWord.isForceInvalid()
orWord.isForceValid()
Also, user word are valid for prediction regardingPredictionParameter.getMinUseCountToValidateNewWord()
- Specified by:
isValidToBePredicted
in interfaceWord
- Parameters:
predictionParameter
- the prediction parameter, could be use to validate the word- Returns:
- true if the word can be displayed in prediction result
-
getProbFactor
public double getProbFactor()
Description copied from interface:Word
This factor can be used to modify final probabilities of the predictions.
It will be applied once probabilities are computed to influence result list.
It is mainly used in a multiplication with the original probability (and then the result list is normalized).
To only rely on probabilities, the value should be 1.0- Specified by:
getProbFactor
in interfaceWord
- Returns:
- the prob factor
-
setProbFactor
public void setProbFactor(double factor, boolean modificationByUser)
Description copied from interface:Word
This factor can be used to modify final probabilities of the predictions.
It will be applied once probabilities are computed to influence result list.
It is mainly used in a multiplication with the original probability (and then the result list is normalized).
To only rely on probabilities, the value should be 1.0- Specified by:
setProbFactor
in interfaceWord
- Parameters:
factor
- the prob factormodificationByUser
- true indicates that the modification was done by the user and not the system
-
isModifiedByUser
public boolean isModifiedByUser()
Description copied from interface:Word
Indicate that this word was modified by the user (e.g. calling a modification method withmodificationByUser
parameter to true)- Specified by:
isModifiedByUser
in interfaceWord
- Returns:
- modification by user flag
-
setModifiedByUser
public void setModifiedByUser(boolean modified)
Description copied from interface:Word
To manually set modification by user flag- Specified by:
setModifiedByUser
in interfaceWord
- Parameters:
modified
- modification by user flag
-
isModifiedBySystem
public boolean isModifiedBySystem()
Description copied from interface:Word
Indicate that this word was modified by the system (e.g. calling a modification method withmodificationByUser
parameter to false)- Specified by:
isModifiedBySystem
in interfaceWord
- Returns:
- modification by system flag
-
setModifiedBySystem
public void setModifiedBySystem(boolean modifiedBySystem)
Description copied from interface:Word
To manually set modification by system flag- Specified by:
setModifiedBySystem
in interfaceWord
- Parameters:
modifiedBySystem
- modification by system flag
-
isModifiedByUserOrSystem
public boolean isModifiedByUserOrSystem()
- Specified by:
isModifiedByUserOrSystem
in interfaceWord
- Returns:
- true if
Word.isModifiedByUser()
orWord.isModifiedBySystem()
-
isForceValid
public boolean isForceValid()
Description copied from interface:Word
To force that this word become valid, mostly use onUserWord
to ignore validation.- Specified by:
isForceValid
in interfaceWord
- Returns:
- force valid enabled
-
setForceValid
public void setForceValid(boolean forceValid, boolean modificationByUser)
Description copied from interface:Word
To force that this word become valid, mostly use onUserWord
to ignore validation.- Specified by:
setForceValid
in interfaceWord
- Parameters:
forceValid
- force valid enabledmodificationByUser
- true indicates that the modification was done by the user and not the system
-
isForceInvalid
public boolean isForceInvalid()
Description copied from interface:Word
To force that this word is invalid.
In fact, this method allow removal of a word from prediction result : words can't be removed from dictionary as they can be used in ngrams, but having forceInvalid true has the same effect than removing a word.- Specified by:
isForceInvalid
in interfaceWord
- Returns:
- force invalid enabled
-
setForceInvalid
public void setForceInvalid(boolean forceInvalid, boolean modificationByUser)
Description copied from interface:Word
To force that this word is invalid.
In fact, this method allow removal of a word from prediction result : words can't be removed from dictionary as they can be used in ngrams, but having forceInvalid true has the same effect than removing a word.- Specified by:
setForceInvalid
in interfaceWord
- Parameters:
forceInvalid
- force invalid enabledmodificationByUser
- true indicates that the modification was done by the user and not the system
-
getUsageCount
public int getUsageCount()
- Specified by:
getUsageCount
in interfaceWord
- Returns:
- the number of times this word was seen "used" in user text.
This count is update byWordPredictor
when training the dynamic model.
-
incrementUsageCount
public void incrementUsageCount()
Description copied from interface:Word
To increase the "usage" count of this word- Specified by:
incrementUsageCount
in interfaceWord
-
getLastUseDate
public long getLastUseDate()
- Specified by:
getLastUseDate
in interfaceWord
- Returns:
- the timestamp of the last usage (typically the last call to
Word.incrementUsageCount()
)
-
-