944,191 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 16146
  • Java RSS
Apr 27th, 2006
0

Word Frequency Count

Expand Post »
I'm supposed to be inserting words from a text file into a BST and AVL tree. I've got the words to insert correctly, and it recognizes whenever the words are repeated. It just leaves the count at 2 instead of incrementing afterwards. Can't seem to figure out why it's not taking the count at the moment it finds a repeat.

Java Syntax (Toggle Plain Text)
  1. try
  2. {
  3. FileReader reader = new FileReader("mlkdream1.txt");
  4. Scanner in = new Scanner(reader);
  5. while (in.hasNext())
  6. {
  7. tmp = in.next();
  8. tmp = tmp.toUpperCase();
  9. word = new WordStat(tmp, 1);
  10.  
  11. if(!Bst1.inTree(word))
  12. {
  13. Bst1.insert(word);
  14. Avl1.insert(word);
  15. count++;
  16. }
  17. else
  18. {
  19. Avl1.retrieve(word);
  20. word.updateCount(1);
  21. Bst1.insert(word);
  22. Avl1.insert(word);
  23. }
  24. }
  25. reader.close();

The variable word is of the type WordStat, which is defined as (String word, int frequency). The updateCount(Integer) method is supposed to grab the original count, and increment it by the number passed to it. I don't think the retrieve is wrong, because that was already written for us.

Any help would be much appreciated
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tigerdude is offline Offline
6 posts
since Mar 2006
Apr 27th, 2006
0

Re: Word Frequency Count

Well when I compare two Strings in java I use this, could that possibly be the problem?
Java Syntax (Toggle Plain Text)
  1. String one = "iamthwee";
  2. String two = "nonsense";
  3.  
  4. if (one.equals(two))
  5. {
  6. System.out.println("Both strings are the same");
  7. }

Whereas I can't explicitly write:
Java Syntax (Toggle Plain Text)
  1. if (one == two)
  2. {
  3. System.out.println("Both strings are the same");
  4. }
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Apr 28th, 2006
0

Re: Word Frequency Count

Well, I was able to find out what was wrong. I was trying to do...

Java Syntax (Toggle Plain Text)
  1. WordStat update;
  2.  
  3. update = Avl1.retrieve(word)

I had a problem in my declarations. It would give me a comparable error everytime. I had forgotten to call Bstree<WordStat>, so that's where I messed up. It compared them correctly, that's what the inTree() function did for me. Anyways, seems there was no point to this post :rolleyes: Thanks for trying to help though.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tigerdude is offline Offline
6 posts
since Mar 2006
Feb 28th, 2010
0
Re: Word Frequency Count
i need the program for word frequency by word length
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asma noreen is offline Offline
1 posts
since Feb 2010
Mar 1st, 2010
0
Re: Word Frequency Count
i need the program for word frequency by word length
Start a new thread and don't expect someone to give you the code unless you show some effort.
Also explain better you problem.
Last edited by javaAddict; Mar 1st, 2010 at 4:56 am.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 447
Nearly a Senior Poster
javaAddict is offline Offline
3,260 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Newbie Trying Again
Next Thread in Java Forum Timeline: Help me to solve this problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC