The Artima Developer Community
Sponsored Link

Java Answers Forum
Advanced Word Frequency

1 reply on 1 page. Most recent reply: Jul 28, 2003 5:47 AM by Vincent O'Sullivan

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
Anup

Posts: 1
Nickname: icefreek
Registered: Jul, 2003

Advanced Word Frequency Posted: Jul 28, 2003 2:40 AM
Reply to this message Reply
Advertisement
I have written the basic Word Frequency Application where the words and their corresponding frequencies are stored in a text file. I always append the frequencies to the bottom of the text file. After running the application a couple of times I always manage to get duplicate values of words. Now what I would like to do is, is to combine the duplicate words and add their frequencies to give me a combined output. Please HELP!!!


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Advanced Word Frequency Posted: Jul 28, 2003 5:47 AM
Reply to this message Reply
One solution might be:
Sort the text file so that the word/count pairs are in alphabetic order.
Process each word/count pair:

previousWordCountPair = firstWordCountPair
for each subsequent WordCountPair in text file
if the current word = previous word then
add the current count to the previous count
else
write the previousWordCountPair (to a new file)
previousWordCountPair = currentWordCountPair
end if
end for
write the previousWordCountPair


Vince

Flat View: This topic has 1 reply on 1 page
Topic: How do I get this to the Window? Previous Topic   Next Topic Topic: Create storage for the list of phrases - arrays HELP?!

Sponsored Links



Google
  Web Artima.com   

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