Package org.predict4all.nlp.words.model
Class SimpleWord
- java.lang.Object
-
- org.predict4all.nlp.words.model.AbstractWord
-
- org.predict4all.nlp.words.model.SimpleWord
-
- All Implemented Interfaces:
Word
- Direct Known Subclasses:
UserWord
public class SimpleWord extends AbstractWord
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
forceInvalid
protected boolean
forceValid
protected boolean
modifiedBySystem
protected boolean
modifiedByUser
protected double
probFactor
protected String
word
-
Fields inherited from interface org.predict4all.nlp.words.model.Word
TYPE_EQUIVALENCE_CLASS, TYPE_NGRAM_TAG, TYPE_SIMPLE, TYPE_USER_WORD
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleWord(int id, String word)
protected
SimpleWord(int id, String word, boolean modifiedByUser, boolean modifiedBySystem, double probFactor, boolean forceInvalid, boolean forceValid)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Word
clone(int newId)
Create a clone of this word.
This allow duplication existing word, an new id should be provided.static SimpleWord
create(int id, String word)
static SimpleWord
createModified(int id, String word, boolean modifiedByUser, boolean modifiedBySystem, double probFactor, boolean forceInvalid, boolean forceValid)
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.0byte
getType()
String
getWord()
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
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
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.0-
Methods inherited from class org.predict4all.nlp.words.model.AbstractWord
getEquivalenceClass, getEquivalenceClassId, getID, getLastUseDate, getNGramTag, getNGramTagId, getUsageCount, incrementUsageCount, isEquivalenceClass, isNGramTag, isUserWord, isValidForSaving, setModifiedBySystem, toString
-
-
-
-
Field Detail
-
word
protected final String word
-
probFactor
protected double probFactor
-
modifiedByUser
protected boolean modifiedByUser
-
modifiedBySystem
protected boolean modifiedBySystem
-
forceValid
protected boolean forceValid
-
forceInvalid
protected boolean forceInvalid
-
-
Method Detail
-
getWord
public String getWord()
- Returns:
- this word "word" ! Can sometimes be null if the word represent a concept more than a real word (e.g.
EquivalenceClassWord
orTagWord
)
-
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
- Overrides:
isValidToBePredicted
in classAbstractWord
- 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
- Overrides:
getProbFactor
in classAbstractWord
- 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
- Overrides:
setProbFactor
in classAbstractWord
- Parameters:
factor
- the prob factormodificationByUser
- true indicates that the modification was done by the user and not the system
-
getType
public byte getType()
- Returns:
- the byte to save this word type (using TYPE_EQUIVALENCE_CLASS, TYPE_NGRAM_TAG, etc...)
Used inWordFileInputStream
andWordFileOutputStream
-
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
- Overrides:
isModifiedByUser
in classAbstractWord
- Returns:
- 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
- Overrides:
isModifiedBySystem
in classAbstractWord
- Returns:
- modification by system flag
-
setModifiedByUser
public void setModifiedByUser(boolean modified)
Description copied from interface:Word
To manually set modification by user flag- Specified by:
setModifiedByUser
in interfaceWord
- Overrides:
setModifiedByUser
in classAbstractWord
- Parameters:
modified
- modification by user flag
-
isModifiedByUserOrSystem
public boolean isModifiedByUserOrSystem()
- Specified by:
isModifiedByUserOrSystem
in interfaceWord
- Overrides:
isModifiedByUserOrSystem
in classAbstractWord
- 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
- Overrides:
isForceValid
in classAbstractWord
- 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
- Overrides:
setForceValid
in classAbstractWord
- 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
- Overrides:
isForceInvalid
in classAbstractWord
- 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
- Overrides:
setForceInvalid
in classAbstractWord
- Parameters:
forceInvalid
- force invalid enabledmodificationByUser
- true indicates that the modification was done by the user and not the system
-
create
public static SimpleWord create(int id, String word)
-
createModified
public static SimpleWord createModified(int id, String word, boolean modifiedByUser, boolean modifiedBySystem, double probFactor, boolean forceInvalid, boolean forceValid)
-
-