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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(CharSequence ngram) Adds anngram
.void
add
(CharSequence chars, int minLength, int maxLength) Adds aCharSequence
that will be ngrammed into chars.boolean
contains
(CharSequence ngram) Checks if the givenngram
is contained in aNGramCharModel
.void
cutoff
(int cutoffUnder, int cutoffOver) Deletes all ngram which do appear less than thecutoffUnder
value and more often than thecutoffOver
value.boolean
int
getCount
(CharSequence ngram) Retrieves the count of the givenngram
.int
hashCode()
iterator()
int
Retrieves the total count of all Ngrams.void
remove
(CharSequence ngram) Removes the specifiedngram
is from aNGramCharModel
.void
setCount
(CharSequence ngram, int count) Sets the count of an existingngram
.int
size()
Retrieves the number ofentries
in 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
- Thengram
to get the count for.- Returns:
- Count of the
ngram
or0
if it is not contained at all.
-
setCount
Sets the count of an existingngram
.- Parameters:
ngram
- Thengram
to get the count for.count
- The count of thengram
to set.
-
add
Adds anngram
. If it already exists the count increase by one.- Parameters:
ngram
- TheCharSequence
to be added.
-
add
Adds aCharSequence
that will be ngrammed into chars.- Parameters:
chars
- TheCharSequence
to 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 specifiedngram
is from aNGramCharModel
.- Parameters:
ngram
- Thengram
to remove. Ifnull
, the model keeps its state.
-
contains
Checks if the givenngram
is contained in aNGramCharModel
.- Parameters:
ngram
- Thengram
to check. Ifnull
, the model keeps its state.- Returns:
true
if the ngram is contained,false
otherwise.
-
size
public int size()Retrieves the number ofentries
in aNGramCharModel
.- Returns:
- Number of different grams or
0
if the model is empty.
-
iterator
- Specified by:
iterator
in 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 thecutoffUnder
value and more often than thecutoffOver
value.- 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()
-