Class NGramLanguageModel
java.lang.Object
opennlp.tools.ngram.NGramModel
opennlp.tools.languagemodel.NGramLanguageModel
- All Implemented Interfaces:
Iterable<StringList>, opennlp.tools.languagemodel.LanguageModel
public class NGramLanguageModel
extends NGramModel
implements opennlp.tools.languagemodel.LanguageModel
A
LanguageModel based on a NGramModel using Stupid Backoff to get
the probabilities of the ngrams.-
Constructor Summary
ConstructorsConstructorDescriptionInitializes 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 Summary
Modifier and TypeMethodDescriptionvoidAdds further tokens.doublecalculateProbability(String... tokens) String[]predictNextTokens(String... tokens) Methods inherited from class NGramModel
add, add, add, contains, cutoff, equals, getCount, hashCode, iterator, numberOfGrams, remove, serialize, setCount, size, toDictionary, toDictionary, toStringMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
NGramLanguageModel
public NGramLanguageModel()Initializes anNGramLanguageModelwithDEFAULT_N. -
NGramLanguageModel
public NGramLanguageModel(int n) Initializes anNGramLanguageModelwith the givennfor the ngram size.- Parameters:
n- The size of the ngrams to be used. Must be greater than0.- Throws:
IllegalArgumentException- Thrown if one of the arguments was invalid.
-
NGramLanguageModel
Initializes aNGramLanguageModelinstance via a validInputStream.- Parameters:
in- TheInputStreamused for loading the model.- Throws:
IOException- Thrown if IO errors occurred during initialization.IllegalArgumentException- Thrown if one of the arguments was invalid.
-
NGramLanguageModel
Initializes aNGramLanguageModelinstance via a validInputStream.- Parameters:
in- TheInputStreamused for loading the model.n- The size of the ngrams to be used. Must be greater than0.- Throws:
IOException- Thrown if IO errors occurred during initialization.IllegalArgumentException- Thrown if one of the arguments was invalid.
-
-
Method Details
-
add
Adds further tokens.- Parameters:
tokens- Text elements to add to theNGramLanguageModel.
-
calculateProbability
- Specified by:
calculateProbabilityin interfaceopennlp.tools.languagemodel.LanguageModel
-
predictNextTokens
-