Package opennlp.tools.languagemodel
Class NGramLanguageModel
java.lang.Object
opennlp.tools.ngram.NGramModel
opennlp.tools.languagemodel.NGramLanguageModel
- All Implemented Interfaces:
- Iterable<StringList>,- LanguageModel
A 
LanguageModel based on a NGramModel using Stupid Backoff to get
 the probabilities of the ngrams.- 
Constructor SummaryConstructorsConstructorDescriptionInitializes anNGramLanguageModelwithDEFAULT_N.NGramLanguageModel(int n) Initializes anNGramLanguageModelwith the givennfor the ngram size.Initializes aNGramLanguageModelinstance via a validInputStream.NGramLanguageModel(InputStream in, int n) Initializes aNGramLanguageModelinstance via a validInputStream.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds further tokens.doublecalculateProbability(String... tokens) Calculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.String[]predictNextTokens(String... tokens) Predict the most probable output sequence of tokens, given an input sequence oftokens.Methods inherited from class opennlp.tools.ngram.NGramModeladd, add, add, contains, cutoff, equals, getCount, hashCode, iterator, numberOfGrams, remove, serialize, setCount, size, toDictionary, toDictionary, toStringMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Constructor Details- 
NGramLanguageModelpublic NGramLanguageModel()Initializes anNGramLanguageModelwithDEFAULT_N.
- 
NGramLanguageModelpublic NGramLanguageModel(int n) Initializes anNGramLanguageModelwith the givennfor the ngram size.- Parameters:
- n- The size of the ngrams to be used. Must be greater than- 0.
- Throws:
- IllegalArgumentException- Thrown if one of the arguments was invalid.
 
- 
NGramLanguageModelInitializes aNGramLanguageModelinstance via a validInputStream.- Parameters:
- in- The- InputStreamused for loading the model.
- Throws:
- IOException- Thrown if IO errors occurred during initialization.
- IllegalArgumentException- Thrown if one of the arguments was invalid.
 
- 
NGramLanguageModelInitializes aNGramLanguageModelinstance via a validInputStream.- Parameters:
- in- The- InputStreamused for loading the model.
- n- The size of the ngrams to be used. Must be greater than- 0.
- Throws:
- IOException- Thrown if IO errors occurred during initialization.
- IllegalArgumentException- Thrown if one of the arguments was invalid.
 
 
- 
- 
Method Details- 
addAdds further tokens.- Parameters:
- tokens- Text elements to add to the- NGramLanguageModel.
 
- 
calculateProbabilityDescription copied from interface:LanguageModelCalculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.- Specified by:
- calculateProbabilityin interface- LanguageModel
- Parameters:
- tokens- the text tokens to calculate the- probabilityfor.
- Returns:
- the probability of the given text tokens in the vocabulary
 
- 
predictNextTokensDescription copied from interface:LanguageModelPredict the most probable output sequence of tokens, given an input sequence oftokens.- Specified by:
- predictNextTokensin interface- LanguageModel
- Parameters:
- tokens- a sequence of tokens
- Returns:
- the most probable subsequent token sequence
 
 
-