Class NGram

  • All Implemented Interfaces:
    Comparable<NGram>

    public class NGram
    extends Object
    implements Comparable<NGram>
    Implementation of an n-gram. An n-gram is a contiguous sequence of n items from a given sequence of text or speech. An item can consist of characters, words, or strings, although typically they model word relationships.
    • Constructor Detail

      • NGram

        public NGram()
        Default constructor for empty NGram
      • NGram

        public NGram​(int n,
                     String... words)
        Creates an NGram of degree n consisting of a list of words.
        Parameters:
        n - The degree of the NGram
        words - The words of the NGram
      • NGram

        public NGram​(int n,
                     List<String> words)
        Creates an NGram of degree n consisting of the list of words.
        Parameters:
        n - The degree of the NGram
        words - The words of the NGram
    • Method Detail

      • getN

        public int getN()
        Gets the N used by this NGram.
        Returns:
        the N used by this NGram
      • getWords

        public List<String> getWords()
        Gets the words in this NGram.
        Returns:
        the words in this NGram
      • getWordN

        public String getWordN​(int index)
        Get the Nth word in this NGram. Uses 0 for the starting index.
        Parameters:
        index - the index of the word in the NGram
        Returns:
        the word at index in this NGram
      • iterator

        public ListIterator<String> iterator()
        Get an iterator over the words of the NGram.
        Returns:
        iterator over the words of the NGram
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object