Package org.predict4all.nlp.words
Class WordDictionary
- java.lang.Object
-
- org.predict4all.nlp.words.WordDictionary
-
public class WordDictionary extends java.lang.Object
Represent a word dictionary.
This dictionary identify each sequence of chars as an unique "word" and keep information for this word (frequency, etc...)
-
-
Constructor Summary
Constructors Constructor Description WordDictionary(LanguageModel languageModel, java.lang.String dictionaryId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
compact()
java.util.Collection<Word>
getAllWords()
java.util.SortedMap<java.lang.String,Word>
getExactWordsWithPrefixExist(java.lang.String prefix)
int
getIDGeneratorState()
java.util.Map<BiIntegerKey,NextWord>
getValidWordForPredictionByPrefix(java.lang.String wordPrefix, PredictionParameter predictionParameter, int wantedWordCount, gnu.trove.set.hash.TIntHashSet wordIdsToExclude)
Returns all the words that starts with a given prefix.
The returned list is not sorted.Word
getWord(int wordId)
Word
getWord(java.lang.String text)
int
getWordId(java.lang.String text)
void
incrementUserWord(int wordId)
boolean
isExactWordWithPrefixExist(java.lang.String prefix)
boolean
isTokenValidToCreateUserWord(Token token)
boolean
isWordExists(java.lang.String text)
static WordDictionary
loadDictionary(LanguageModel languageModel, java.io.File dictionaryFile)
void
loadUserDictionary(java.io.File userDictionaryFile)
Word
putUserWord(java.lang.String word)
int
putUserWord(Token token)
int
putWordTraining(java.lang.String word)
void
saveUserDictionary(java.io.File userDictionaryFile)
int
size()
-
-
-
Constructor Detail
-
WordDictionary
public WordDictionary(LanguageModel languageModel, java.lang.String dictionaryId)
-
-
Method Detail
-
getWordId
public int getWordId(java.lang.String text)
-
getWord
public Word getWord(java.lang.String text)
-
getWord
public Word getWord(int wordId)
-
getValidWordForPredictionByPrefix
public java.util.Map<BiIntegerKey,NextWord> getValidWordForPredictionByPrefix(java.lang.String wordPrefix, PredictionParameter predictionParameter, int wantedWordCount, gnu.trove.set.hash.TIntHashSet wordIdsToExclude)
Returns all the words that starts with a given prefix.
The returned list is not sorted.- Parameters:
wordPrefix
- prefixpredictionParameter
- prediction parameters (used to validate word to predict)wantedWordCount
- the number of word wanted (used to stop search)wordIdsToExclude
- to exclude word from the result set (by id)- Returns:
- the list of all word starting with the given prefix
-
getAllWords
public java.util.Collection<Word> getAllWords()
-
size
public int size()
-
isExactWordWithPrefixExist
public boolean isExactWordWithPrefixExist(java.lang.String prefix)
-
getExactWordsWithPrefixExist
public java.util.SortedMap<java.lang.String,Word> getExactWordsWithPrefixExist(java.lang.String prefix)
-
getIDGeneratorState
public int getIDGeneratorState()
-
putUserWord
public int putUserWord(Token token)
-
putUserWord
public Word putUserWord(java.lang.String word)
-
incrementUserWord
public void incrementUserWord(int wordId)
-
isWordExists
public boolean isWordExists(java.lang.String text)
-
isTokenValidToCreateUserWord
public boolean isTokenValidToCreateUserWord(Token token)
-
putWordTraining
public int putWordTraining(java.lang.String word)
-
compact
public void compact()
-
loadDictionary
public static WordDictionary loadDictionary(LanguageModel languageModel, java.io.File dictionaryFile) throws java.io.IOException, WordDictionaryMatchingException
- Throws:
java.io.IOException
WordDictionaryMatchingException
-
loadUserDictionary
public void loadUserDictionary(java.io.File userDictionaryFile) throws java.io.IOException, WordDictionaryMatchingException
- Throws:
java.io.IOException
WordDictionaryMatchingException
-
saveUserDictionary
public void saveUserDictionary(java.io.File userDictionaryFile) throws java.io.IOException
- Throws:
java.io.IOException
-
-