Class Vocabulary

java.lang.Object
Vocabulary

public class Vocabulary extends Object
  • Constructor Details

    • Vocabulary

      public Vocabulary()
      Create a new vocabulary object with empty lists of starting words and no word pairs.
  • Method Details

    • addStartingWord

      public void addStartingWord(String word)
      Add a starting word occurrence. Duplicate words are permitted and are retained, not discarded.
      Parameters:
      word - a word that can begin a new sentence
    • addWordPair

      public void addWordPair(String lastWord, String word)
      Add a word pair from a document. Duplicate pairs are permitted and are retained, not discarded.
      Parameters:
      lastWord - a word that can precede another
      word - a word that can follow lastWord
    • getNumStartingWords

      public int getNumStartingWords()
      Number of word occurrences that can start a sentence.
      Returns:
      number of sentence-starting words
    • getNumWordPairs

      public int getNumWordPairs()
      Number of word pairs (preceding-word, following-word) that have been entered.
      Returns:
      number of work pairs
    • getStartingWords

      public List<String> getStartingWords()
      Get a list of all known starting words, in the order added. If no starting words have been added, returns a list of length 0.
      Returns:
      list of starting words
    • getWordsThatCanFollow

      public List<String> getWordsThatCanFollow(String lastWord)
      Returns a list of all words that are known to have followed lastWord, in the order added. If no such words exist, returns a list of length 0.