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!!!
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