Class Document

java.lang.Object
edu.odu.cs.cs350.Document

public class Document extends Object
Represents a text document containing a collection of words.

Each Document tracks the frequency of each word using Word objects.

  • Constructor Details

    • Document

      public Document(String name)
      Constructs a new Document with the specified name.
      Parameters:
      name - the name of the document (usually the file name)
  • Method Details

    • getName

      public String getName()
      Returns the name of this document.
      Returns:
      the document name
    • addWord

      public void addWord(String w)
      Adds a word to this document with an initial count of 1 or increments its count if the word has already been seen.
      Parameters:
      w - the word to add
    • getWords

      public Map<String,Word> getWords()
      Returns the map of words contained in this document.
      Returns:
      a map where keys are word strings and values are Word objects
    • getTotalWordCount

      public int getTotalWordCount()
      Calculates the total number of words (sum of all word counts) in this document.
      Returns:
      the total word count