Class Word

java.lang.Object
  extended by 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.
 
Method Summary
 int compareTo(java.lang.Object o)
           
 boolean equals(Word w)
           
 int getFreq()
           
 java.lang.String getWord()
           
 void incFreq()
           
static Word[] loadDictionary(java.lang.String fileName)
          Load a dictionary file into a Word array.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

word

protected java.lang.String word

freq

protected int freq
Constructor Detail

Word

public Word(java.lang.String w,
            int f)
Construct a Word object.

Parameters:
w - a String representing a word
f - an int representing the frequency of the word in a language
Method Detail

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