The Artima Developer Community
Sponsored Link

Java Answers Forum
hashtabel help..urgent

1 reply on 1 page. Most recent reply: Apr 9, 2003 7:30 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
claudia C

Posts: 1
Nickname: zeiffelz
Registered: Mar, 2003

hashtabel help..urgent Posted: Mar 31, 2003 5:53 PM
Reply to this message Reply
Advertisement
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


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: hashtabel help..urgent Posted: Apr 9, 2003 7:30 AM
Reply to this message Reply
Don't you think if you convert all the words to upper case it before adding to the hashtable it would be easy to find the frequency...???

Flat View: This topic has 1 reply on 1 page
Topic: Connection reset by peer: JVM_recv in socket input stream read Previous Topic   Next Topic Topic: download image by java program?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use