Class Word
java.lang.Object
Word
- All Implemented Interfaces:
- java.lang.Comparable
- Direct Known Subclasses:
- EncodedWord
public class Word
- extends java.lang.Object
- implements java.lang.Comparable
A class to store a word and its frequency in a language.
- Author:
- Scott MacKenzie, 2001-2005
Field Summary |
protected int |
freq
|
protected java.lang.String |
word
|
Constructor Summary |
Word(java.lang.String w,
int f)
Construct a Word object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
word
protected java.lang.String word
freq
protected int freq
Word
public Word(java.lang.String w,
int f)
- Construct a Word object.
- Parameters:
w
- a String representing a wordf
- an int representing the frequency of the word in a language
getWord
public java.lang.String getWord()
getFreq
public int getFreq()
incFreq
public void incFreq()
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
loadDictionary
public static Word[] loadDictionary(java.lang.String fileName)
throws java.io.IOException
- Load a dictionary file into a
Word
array.
A dictionary file contains a series of lines, each containing
two white-space delimited entries: a word and the frequency
of the word in the target language.
As an example of a dictionary file, here are a few lines from
the file d1-wordfreq.txt
:
any 108043
only 105411
people 102516
than 101495
should 99069
like 87862
between 87034
very 86823
- Parameters:
fileName
- the name of the dictionary file
- Returns:
- a
Word
array.
- Throws:
java.io.IOException
equals
public boolean equals(Word w)
compareTo
public int compareTo(java.lang.Object o)
- Specified by:
compareTo
in interface java.lang.Comparable