Class NGramCharModel

java.lang.Object
opennlp.tools.ngram.NGramCharModel
All Implemented Interfaces:
Iterable<CharSequence>

public class NGramCharModel extends Object implements Iterable<CharSequence>
The NGramCharModel can be used to create character ngrams.
See Also:
  • Constructor Details

    • NGramCharModel

      public NGramCharModel()
      Initializes an empty instance.
  • Method Details

    • getCount

      public int getCount(CharSequence ngram)
      Retrieves the count of the given ngram.
      Parameters:
      ngram - The ngram to get the count for.
      Returns:
      Count of the ngram or 0 if it is not contained at all.
    • setCount

      public void setCount(CharSequence ngram, int count)
      Sets the count of an existing ngram.
      Parameters:
      ngram - The ngram to get the count for.
      count - The count of the ngram to set.
    • add

      public void add(CharSequence ngram)
      Adds an ngram. If it already exists the count increase by one.
      Parameters:
      ngram - The CharSequence to be added.
    • add

      public void add(CharSequence chars, int minLength, int maxLength)
      Adds a CharSequence that will be ngrammed into chars.
      Parameters:
      chars - The CharSequence to be ngrammed.
      minLength - The minimal length for 'n' to populate ngrams with.
      maxLength - The maximum length for 'n' to populate ngrams with.
    • remove

      public void remove(CharSequence ngram)
      Removes the specified ngram is from a NGramCharModel.
      Parameters:
      ngram - The ngram to remove. If null, the model keeps its state.
    • contains

      public boolean contains(CharSequence ngram)
      Checks if the given ngram is contained in a NGramCharModel.
      Parameters:
      ngram - The ngram to check. If null, the model keeps its state.
      Returns:
      true if the ngram is contained, false otherwise.
    • size

      public int size()
      Retrieves the number of entries in a NGramCharModel.
      Returns:
      Number of different grams or 0 if the model is empty.
    • iterator

      public Iterator<CharSequence> iterator()
      Retrieves an Iterator over all entries.
      Specified by:
      iterator in interface Iterable<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 the cutoffUnder value and more often than the cutoffOver value.
      Parameters:
      cutoffUnder - The lower boundary to use for deletions. Must be greater than 0.
      cutoffOver - The upper boundary to use for deletions. Must be greater than 0
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object