Class NGramUtils
Utility class for ngrams. Some methods apply specifically to certain 'n' values, for e.g. tri/bi/uni-grams.
public static class NGramUtils
- Inheritance
-
NGramUtils
- Inherited Members
Methods
CalculateBigramMLProbability(string, string, ICollection<StringList>)
Calculate the probability of a bigram in a vocabulary using maximum likelihood estimation.
public static double CalculateBigramMLProbability(string x0, string x1, ICollection<StringList> set)
Parameters
x0stringfirst word in the bigram
x1stringsecond word in the bigram
setICollection<StringList>the vocabulary
Returns
- double
the maximum likelihood probability
CalculateBigramPriorSmoothingProbability(string, string, ICollection<StringList>, double)
Calculate the probability of a bigram in a vocabulary using prior Laplace smoothing algorithm.
public static double CalculateBigramPriorSmoothingProbability(string x0, string x1, ICollection<StringList> set, double k)
Parameters
x0stringthe first word in the bigram
x1stringthe second word in the bigram
setICollection<StringList>the vocabulary
kdoublethe smoothing factor
Returns
- double
the prior Laplace smoothing probability
CalculateLaplaceSmoothingProbability(StringList, IEnumerable<StringList>, double)
Calculate the probability of a ngram in a vocabulary using Laplace smoothing algorithm.
public static double CalculateLaplaceSmoothingProbability(StringList ngram, IEnumerable<StringList> set, double k)
Parameters
ngramStringListthe ngram to get the probability for
setIEnumerable<StringList>the vocabulary
kdoublethe smoothing factor
Returns
- double
the Laplace smoothing probability
- See Also
CalculateMissingNgramProbabilityMass(StringList, double, IEnumerable<StringList>)
Calculate the probability of a ngram in a vocabulary using the missing probability mass algorithm.
public static double CalculateMissingNgramProbabilityMass(StringList ngram, double discount, IEnumerable<StringList> set)
Parameters
ngramStringListthe ngram
discountdoublediscount factor
setIEnumerable<StringList>the vocabulary
Returns
- double
the probability
CalculateNgramMLProbability(StringList, IEnumerable<StringList>)
Calculate the probability of a ngram in a vocabulary using maximum likelihood estimation.
public static double CalculateNgramMLProbability(StringList ngram, IEnumerable<StringList> set)
Parameters
ngramStringLista ngram
setIEnumerable<StringList>the vocabulary
Returns
- double
the maximum likelihood probability
CalculateTrigramLinearInterpolationProbability(string, string, string, ICollection<StringList>, double, double, double)
Calculate the probability of a trigram in a vocabulary using a linear interpolation algorithm.
public static double CalculateTrigramLinearInterpolationProbability(string x0, string x1, string x2, ICollection<StringList> set, double lambda1, double lambda2, double lambda3)
Parameters
x0stringthe first word in the trigram
x1stringthe second word in the trigram
x2stringthe third word in the trigram
setICollection<StringList>the vocabulary
lambda1doubletrigram interpolation factor
lambda2doublebigram interpolation factor
lambda3doubleunigram interpolation factor
Returns
- double
the linear interpolation probability
CalculateTrigramMLProbability(string, string, string, IEnumerable<StringList>)
Calculate the probability of a trigram in a vocabulary using maximum likelihood estimation.
public static double CalculateTrigramMLProbability(string x0, string x1, string x2, IEnumerable<StringList> set)
Parameters
x0stringfirst word in the trigram
x1stringsecond word in the trigram
x2stringthird word in the trigram
setIEnumerable<StringList>the vocabulary
Returns
- double
the maximum likelihood probability
CalculateUnigramMLProbability(string, ICollection<StringList>)
Calculate the probability of a unigram in a vocabulary using maximum likelihood estimation.
public static double CalculateUnigramMLProbability(string word, ICollection<StringList> set)
Parameters
wordstringthe only word in the unigram
setICollection<StringList>the vocabulary
Returns
- double
the maximum likelihood probability
GetNGrams(StringList, int)
Get the ngrams of dimension n of a certain input sequence of tokens.
public static ICollection<StringList> GetNGrams(StringList sequence, int size)
Parameters
sequenceStringLista sequence of tokens
sizeintthe size of the resulting ngrams
Returns
- ICollection<StringList>
all the possible ngrams of the given size derivable from the input sequence
GetNGrams(string[], int)
Get the ngrams of dimension n of a certain input sequence of tokens.
public static ICollection<string[]> GetNGrams(string[] sequence, int size)
Parameters
Returns
- ICollection<string[]>
all the possible ngrams of the given size derivable from the input sequence
GetNMinusOneTokenFirst(StringList)
Get the (n-1)th ngram of a given ngram, that is the same ngram except the last word in the ngram.
public static StringList? GetNMinusOneTokenFirst(StringList ngram)
Parameters
ngramStringLista ngram
Returns
- StringList
a ngram, or
nullif the given ngram holds a single token
GetNMinusOneTokenLast(StringList)
Get the (n-1)th ngram of a given ngram, that is the same ngram except the first word in the ngram.
public static StringList? GetNMinusOneTokenLast(StringList ngram)
Parameters
ngramStringLista ngram
Returns
- StringList
a ngram, or
nullif the given ngram holds a single token