public class Word
extends java.lang.Object
implements java.lang.Comparable<java.lang.Object>
Modifier and Type | Field and Description |
---|---|
protected int |
freq |
protected java.lang.String |
word |
Constructor and Description |
---|
Word(java.lang.String w,
int f)
Construct a Word object.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.lang.Object o) |
boolean |
equals(Word w) |
int |
getFreq() |
java.lang.String |
getWord() |
static Word[] |
loadDictionary(java.lang.String fileName)
Load a dictionary file into a
Word array. |
java.lang.String |
toString() |
public Word(java.lang.String w, int f)
w
- a String representing a wordf
- an int representing the frequency of the word in a languagepublic static Word[] loadDictionary(java.lang.String fileName) throws java.io.IOException
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
fileName
- the name of the dictionary fileWord
array.java.io.IOException
public java.lang.String getWord()
public int getFreq()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(Word w)
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable<java.lang.Object>