Class NGramModel
The NGramModel can be used to crate ngrams and character ngrams.
public class NGramModel : IEnumerable<StringList>, IEnumerable
- Inheritance
-
NGramModel
- Implements
- Derived
- Inherited Members
Constructors
NGramModel()
Initializes an empty instance.
public NGramModel()
NGramModel(Stream)
Initializes the current instance.
public NGramModel(Stream @in)
Parameters
inStreamthe serialized model stream
Exceptions
Fields
COUNT
protected const string COUNT = "count"
Field Value
Properties
Count
Retrieves the number of StringList entries in the current instance.
public virtual int Count { get; }
Property Value
- int
number of different grams
NumberOfGrams
Retrieves the total count of all Ngrams.
public virtual int NumberOfGrams { get; }
Property Value
- int
total count of all ngrams
Methods
Add(StringList)
Adds one NGram, if it already exists the count increase by one.
public virtual void Add(StringList ngram)
Parameters
ngramStringList
Add(StringList, int, int)
Adds NGrams up to the specified length to the current instance.
public virtual void Add(StringList ngram, int minLength, int maxLength)
Parameters
ngramStringListthe tokens to build the uni-grams, bi-grams, tri-grams, .. from.
minLengthint- minimal length
maxLengthint- maximal length
Add(string, int, int)
Adds character NGrams to the current instance.
public virtual void Add(string chars, int minLength, int maxLength)
Parameters
Contains(StringList)
Checks fit he given tokens are contained by the current instance.
public virtual bool Contains(StringList tokens)
Parameters
tokensStringList
Returns
- bool
true if the ngram is contained
Cutoff(int, int)
Deletes all ngram which do appear less than the cutoffUnder value and more often than the cutoffOver value.
public virtual void Cutoff(int cutoffUnder, int cutoffOver)
Parameters
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetCount(StringList)
Retrieves the count of the given ngram.
public virtual int GetCount(StringList ngram)
Parameters
ngramStringListan ngram
Returns
- int
count of the ngram or 0 if it is not contained
GetEnumerator()
Retrieves an IEnumerator<T> over all StringList entries.
public IEnumerator<StringList> GetEnumerator()
Returns
- IEnumerator<StringList>
iterator over all grams
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Remove(StringList)
Removes the specified tokens form the NGram model, they are just dropped.
public virtual void Remove(StringList tokens)
Parameters
tokensStringList
Serialize(Stream)
Writes the ngram instance to the given Stream.
public virtual void Serialize(Stream @out)
Parameters
Exceptions
- IOException
if writing to the Stream fails
SetCount(StringList, int)
Sets the count of an existing ngram.
public virtual void SetCount(StringList ngram, int count)
Parameters
ngramStringListcountint
ToDictionary()
Creates a dictionary which contain all StringList which are in the current NGramModel.
Entries which are only different in the case are merged into one.
Calling this method is the same as calling ToDictionary(bool) with true.
public virtual Dictionary ToDictionary()
Returns
- Dictionary
a dictionary of the ngrams
ToDictionary(bool)
Creates a dictionary which contains all StringLists which are in the current NGramModel.
public virtual Dictionary ToDictionary(bool caseSensitive)
Parameters
caseSensitiveboolSpecifies whether case distinctions should be kept in the creation of the dictionary.
Returns
- Dictionary
a dictionary of the ngrams
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.