Package opennlp.tools.ngram
Class NGramCharModel
java.lang.Object
opennlp.tools.ngram.NGramCharModel
- All Implemented Interfaces:
Iterable<CharSequence>
The
NGramCharModel can be used to create character ngrams.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(CharSequence ngram) Adds anngram.voidadd(CharSequence chars, int minLength, int maxLength) Adds aCharSequencethat will be ngrammed into chars.booleancontains(CharSequence ngram) Checks if the givenngramis contained in aNGramCharModel.voidcutoff(int cutoffUnder, int cutoffOver) Deletes all ngram which do appear less than thecutoffUndervalue and more often than thecutoffOvervalue.booleanintgetCount(CharSequence ngram) Retrieves the count of the givenngram.inthashCode()iterator()intRetrieves the total count of all Ngrams.voidremove(CharSequence ngram) Removes the specifiedngramis from aNGramCharModel.voidsetCount(CharSequence ngram, int count) Sets the count of an existingngram.intsize()Retrieves the number ofentriesin aNGramCharModel.toString()Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
NGramCharModel
public NGramCharModel()Initializes an empty instance.
-
-
Method Details
-
getCount
Retrieves the count of the givenngram.- Parameters:
ngram- Thengramto get the count for.- Returns:
- Count of the
ngramor0if it is not contained at all.
-
setCount
Sets the count of an existingngram.- Parameters:
ngram- Thengramto get the count for.count- The count of thengramto set.
-
add
Adds anngram. If it already exists the count increase by one.- Parameters:
ngram- TheCharSequenceto be added.
-
add
Adds aCharSequencethat will be ngrammed into chars.- Parameters:
chars- TheCharSequenceto be ngrammed.minLength- The minimal length for'n'to populate ngrams with.maxLength- The maximum length for'n'to populate ngrams with.
-
remove
Removes the specifiedngramis from aNGramCharModel.- Parameters:
ngram- Thengramto remove. Ifnull, the model keeps its state.
-
contains
Checks if the givenngramis contained in aNGramCharModel.- Parameters:
ngram- Thengramto check. Ifnull, the model keeps its state.- Returns:
trueif the ngram is contained,falseotherwise.
-
size
public int size()Retrieves the number ofentriesin aNGramCharModel.- Returns:
- Number of different grams or
0if the model is empty.
-
iterator
- Specified by:
iteratorin interfaceIterable<CharSequence>- Returns:
- iterator over all ngrams
-
numberOfGrams
public int numberOfGrams()Retrieves the total count of all Ngrams.- Returns:
- total count of all ngrams
-
cutoff
public void cutoff(int cutoffUnder, int cutoffOver) Deletes all ngram which do appear less than thecutoffUndervalue and more often than thecutoffOvervalue.- Parameters:
cutoffUnder- The lower boundary to use for deletions. Must be greater than0.cutoffOver- The upper boundary to use for deletions. Must be greater than0
-
equals
-
toString
-
hashCode
public int hashCode()
-