Package opennlp.tools.languagemodel
Class NGramLanguageModel
- java.lang.Object
-
- opennlp.tools.ngram.NGramModel
-
- opennlp.tools.languagemodel.NGramLanguageModel
-
- All Implemented Interfaces:
Iterable<StringList>,LanguageModel
public class NGramLanguageModel extends NGramModel implements LanguageModel
ALanguageModelbased on aNGramModelusing Stupid Backoff to get the probabilities of the ngrams.
-
-
Constructor Summary
Constructors Constructor Description NGramLanguageModel()NGramLanguageModel(int n)NGramLanguageModel(InputStream in)NGramLanguageModel(InputStream in, int n)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String... tokens)doublecalculateProbability(String... tokens)Calculate the probability of a series of tokens (e.g.doublecalculateProbability(StringList tokens)Calculate the probability of a series of tokens (e.g.String[]predictNextTokens(String... tokens)Predict the most probable output sequence of tokens, given an input sequence of tokens.StringListpredictNextTokens(StringList tokens)Predict the most probable output sequence of tokens, given an input sequence of tokens.-
Methods inherited from class opennlp.tools.ngram.NGramModel
add, add, add, contains, cutoff, equals, getCount, hashCode, iterator, numberOfGrams, remove, serialize, setCount, size, toDictionary, toDictionary, toString
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
NGramLanguageModel
public NGramLanguageModel()
-
NGramLanguageModel
public NGramLanguageModel(int n)
-
NGramLanguageModel
public NGramLanguageModel(InputStream in) throws IOException
- Throws:
IOException
-
NGramLanguageModel
public NGramLanguageModel(InputStream in, int n) throws IOException
- Throws:
IOException
-
-
Method Detail
-
add
public void add(String... tokens)
-
calculateProbability
public double calculateProbability(StringList tokens)
Description copied from interface:LanguageModelCalculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.- Specified by:
calculateProbabilityin interfaceLanguageModel- Parameters:
tokens- the text tokens to calculate the probability for- Returns:
- the probability of the given text tokens in the vocabulary
-
calculateProbability
public double calculateProbability(String... tokens)
Description copied from interface:LanguageModelCalculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.- Specified by:
calculateProbabilityin interfaceLanguageModel- Parameters:
tokens- the text tokens to calculate the probability for- Returns:
- the probability of the given text tokens in the vocabulary
-
predictNextTokens
public StringList predictNextTokens(StringList tokens)
Description copied from interface:LanguageModelPredict the most probable output sequence of tokens, given an input sequence of tokens.- Specified by:
predictNextTokensin interfaceLanguageModel- Parameters:
tokens- a sequence of tokens- Returns:
- the most probable subsequent token sequence
-
predictNextTokens
public String[] predictNextTokens(String... tokens)
Description copied from interface:LanguageModelPredict the most probable output sequence of tokens, given an input sequence of tokens.- Specified by:
predictNextTokensin interfaceLanguageModel- Parameters:
tokens- a sequence of tokens- Returns:
- the most probable subsequent token sequence
-
-