Hi!! How do u use a hashtable to get the word freuency if it contains both words and numbers? i cannot use java.util.Habletable or String.hashCode ()....need to implement own hashtable and function eg. Input: This appears three times in this test some words contain digits such as 10mar 2003 # This test 10mar 2003
The input has two parts separated by a line containing only one "#" character.
The first part is a text file. Each line contains a few words separated by spaces (some lines maybe empty). No punctuation. However, words may appear in mixed cases. For example, "This" and "this" shall be counted as same. Some words may contain digits, for example "10mar". I just treat each word as a string. The second part consists of a few lines, each line contains exactly one word. For every word I wanna find its frequency in the first part.
Anyone can help me? Thank you very much!!
a lot of blank parts..dont know what to write cos i just learn java in last than 6 months...
public class Main1 { public static void main (String [] args) throws IOException { //read input from file FileInputStream infile = new FileInputStream ("input.dat"); BufferedReader stdin = new BufferedReader (new InputStreamReader (infile));
//read all the words as string String s;
while ((s = stdin.readLine ()) != null) { //Output is uppercase, so initialise first s1 = s.toUpperCase (); //Get rid of spaces StringTokenizer st = new StringTokenizer (s1, " "); //Store into vector Vector V = new Vector ();
while (st.hasMoreTokens ()) { //Get posuion of # int position = String.indexOf ("#"); //Get position of last word to get the size of array int end =
HashTable hashtable1 = new HashTable ();
for (int i = 0; i < position; i++) { //Store into vector V.addElement (String.valueOf (i)); } for (int j = position, j < end; j++) { //Put into array Word word1 = new Word (" ", 0); hashtable1.add (word); } for (int i = hashtable.size (); i++) { // compare the words with those in infile and get word count word = hashTable ; for (int j = 0; j < V.size (); j++) { //find word if ((word.the_word)equals (V.elementAt [j])) { word.count++; } } } printResults (hashtable1); } } infile.close (); }//End of main }//End of class Main1
public class HashTable { Word [] Table; int
void add(); int hash (String key) { }
}//End of class HashTable
public class Word { String the_word; int count; }//End of class