Package edu.odu.cs.cs350
Class Document
java.lang.Object
edu.odu.cs.cs350.Document
Represents a text document containing a collection of words.
Each Document tracks the frequency of each word using Word objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a word to this document with an initial count of 1 or increments its count if the word has already been seen.getName()Returns the name of this document.intCalculates the total number of words (sum of all word counts) in this document.getWords()Returns the map of words contained in this document.
-
Constructor Details
-
Document
Constructs a new Document with the specified name.- Parameters:
name- the name of the document (usually the file name)
-
-
Method Details
-
getName
Returns the name of this document.- Returns:
- the document name
-
addWord
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
Returns the map of words contained in this document.- Returns:
- a map where keys are word strings and values are
Wordobjects
-
getTotalWordCount
public int getTotalWordCount()Calculates the total number of words (sum of all word counts) in this document.- Returns:
- the total word count
-