Class NGramCharModel

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>

    public class NGramCharModel
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.String>
    The NGramCharModel can be used to create character ngrams.
    • Constructor Summary

      Constructors 
      Constructor Description
      NGramCharModel()
      Initializes an empty instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.CharSequence chars, int minLength, int maxLength)
      Adds CharSequence that will be ngrammed into chars.
      void add​(java.lang.String ngram)
      Adds one NGram, if it already exists the count increase by one.
      boolean contains​(java.lang.String ngram)
      Checks fit he given tokens are contained by the current instance.
      void cutoff​(int cutoffUnder, int cutoffOver)
      Deletes all ngram which do appear less than the cutoffUnder value and more often than the cutoffOver value.
      boolean equals​(java.lang.Object obj)  
      int getCount​(java.lang.String ngram)
      Retrieves the count of the given ngram.
      int hashCode()  
      java.util.Iterator<java.lang.String> iterator()
      Retrieves an Iterator over all String entries.
      int numberOfGrams()
      Retrieves the total count of all Ngrams.
      void remove​(java.lang.String ngram)
      Removes the specified tokens form the NGram model, they are just dropped.
      void setCount​(java.lang.String ngram, int count)
      Sets the count of an existing ngram.
      int size()
      Retrieves the number of String entries in the current instance.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • NGramCharModel

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

      • getCount

        public int getCount​(java.lang.String ngram)
        Retrieves the count of the given ngram.
        Parameters:
        ngram - an ngram
        Returns:
        count of the ngram or 0 if it is not contained
      • setCount

        public void setCount​(java.lang.String ngram,
                             int count)
        Sets the count of an existing ngram.
        Parameters:
        ngram -
        count -
      • add

        public void add​(java.lang.String ngram)
        Adds one NGram, if it already exists the count increase by one.
        Parameters:
        ngram -
      • add

        public void add​(java.lang.CharSequence chars,
                        int minLength,
                        int maxLength)
        Adds CharSequence that will be ngrammed into chars.
        Parameters:
        chars -
        minLength -
        maxLength -
      • remove

        public void remove​(java.lang.String ngram)
        Removes the specified tokens form the NGram model, they are just dropped.
        Parameters:
        ngram -
      • contains

        public boolean contains​(java.lang.String ngram)
        Checks fit he given tokens are contained by the current instance.
        Parameters:
        ngram -
        Returns:
        true if the ngram is contained
      • size

        public int size()
        Retrieves the number of String entries in the current instance.
        Returns:
        number of different grams
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Retrieves an Iterator over all String entries.
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Returns:
        iterator over all grams
      • 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 -
        cutoffOver -
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

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

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object