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
ALanguageModel
based on aNGramModel
using 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 void
add(String... tokens)
double
calculateProbability(String... tokens)
Calculate the probability of a series of tokens (e.g.double
calculateProbability(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.StringList
predictNextTokens(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:LanguageModel
Calculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.- Specified by:
calculateProbability
in 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:LanguageModel
Calculate the probability of a series of tokens (e.g. a sentence), given a vocabulary.- Specified by:
calculateProbability
in 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:LanguageModel
Predict the most probable output sequence of tokens, given an input sequence of tokens.- Specified by:
predictNextTokens
in interfaceLanguageModel
- Parameters:
tokens
- a sequence of tokens- Returns:
- the most probable subsequent token sequence
-
predictNextTokens
public String[] predictNextTokens(String... tokens)
Description copied from interface:LanguageModel
Predict the most probable output sequence of tokens, given an input sequence of tokens.- Specified by:
predictNextTokens
in interfaceLanguageModel
- Parameters:
tokens
- a sequence of tokens- Returns:
- the most probable subsequent token sequence
-
-