Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > word frequency counter


Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2001, 06:27 PM
Albert
Guest
 
Posts: n/a
Default word frequency counter

I would appreciate any kind of help!
The problem is:
the program accepts an ASCII text file (sequential file) for input and counts the number of occurences of each word in the file. The results are stored in a user-designated output file (random-access file).
A sample input file appears below:
The dog went to the yard.
the output file is as follows:
the 2
dog 1
went 1
to 1
yard 1
(don't count punctuation mark as part of the word)
No arrays may be used
Thank you
Albert

Reply With Quote
  #2  
Old 03-30-2001, 07:58 AM
anhmytran anhmytran is offline
Senior Contributor

Retired Moderator
* Guru *
 
Join Date: Aug 1999
Location: Hartford, Connecticut, 06
Posts: 1,487
Default Re: word frequency counter

1- You should not tell programmer how to do when you ask for help
The programmer knows better than you do.
2- You should not tell programmer what kind of file the input and output will be.
For the sample you gave is not Sequential nor Random access file.
3- The program pseudocodes is simple, but the syntax requires much
tedios tasks: There is another text file for temporary use rather than an array.
There is a grand Loop from the first word to the last in the input text file.
In each loop, the program checks the temporary file to find a match (a sub loop).
If not found, it writes the new word in the temporary file, and starts to
cound the occurence of the word in the input file, and writes to the output file
(another sub loop).

This program is simple and boring. I am sorry I am not interested in it.

AnhMy_Tran
Reply With Quote
  #3  
Old 03-30-2001, 10:38 AM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Re: word frequency counter

Obviously, this is a homework question so you're not likely to get a complete answer...

Why would your teacher forbid arrays? It would make the code a lot simpler...

The first part of your problem is to parse the input into words. You can do this by first stripping all the punctuation out of it. One way to do that is by using the replace command. For instance:
replace(s$,".","")
deletes all periods in s$
Then you could use the split function to get an array of words. Hmm...no arrays...
Well then, I guess you could use the instr() function to look for each space, then extract the word with the mid$() function.

Since you can't use arrays and since you have no idea how many words you will have, it makes storing the individual words difficult. One way to do it would be to use a string with a CSV format to store all the words and numbers. Another would be to use a listbox and put the frequency in the itemdata property. This is sort of an array though and might be disqualified. Finally, you could write the words to a file. This way requires a *lot* of file access activity so your program will run pretty slow. It's probably the way your teacher wants though since it minimizes RAM requirements.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #4  
Old 03-30-2001, 11:13 AM
klabranche klabranche is offline
Junior Contributor
 
Join Date: May 2000
Location: Arizona
Posts: 288
Default Re: word frequency counter

Don't be so hard anhmytran. If you don't want to answer the question then don't say anything. This is an obvious Homework assignment and they were simply giving the guidelines for it.

[img]images/icons/smile.gif[/img]<P ID="edit"><FONT class="small"><EM>Edited by klabranche on 03/30/01 12:27 PM.</EM></FONT></P>
Reply With Quote
  #5  
Old 03-30-2001, 11:32 AM
anhmytran anhmytran is offline
Senior Contributor

Retired Moderator
* Guru *
 
Join Date: Aug 1999
Location: Hartford, Connecticut, 06
Posts: 1,487
Default Re: word frequency counter

Thank you klabranche:

I do not mean hard. I am sorry my word sound hard.

I add in to my previous post that when a word is added
to the temporary file, every occurence of it is replaced
by a vbNullString, so that it cannot be found and counted
again. In doing so, the input data becomes less and less
after every loop. The input data can be stored in RAM.

AnhMy_Tran
Reply With Quote
  #6  
Old 03-30-2001, 11:35 AM
klabranche klabranche is offline
Junior Contributor
 
Join Date: May 2000
Location: Arizona
Posts: 288
Default Re: word frequency counter

Anhmytran,
Cool... I know you are not trying to blast anyone on purpose.

[img]images/icons/smile.gif[/img]
Reply With Quote
  #7  
Old 03-30-2001, 11:51 PM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Default Re: word frequency counter

Hey, I see you've experience some of the "POSTER" nono's! Look, none of these gentlemen are angry with you, but you must realize that you are coming here for help. Specific detials are good to suggest (i enforce suggest) but not to demand them. it seems, however, that you've ended up with no ideas, or possible solutions to your problem.

I've thrown a function together that will parse your string and calculate and remove the repeated words. However, i didn't check for punctuation or use a sequential file nor did i use a random access file. That parts up to you.

Experience is the best source of knowledge!!

Don't worry about that ANHMYTRAN, he's an excellent programmer that can offer many solutions, but watch out for his CRANKY moments [img]images/icons/smile.gif[/img]

good luck !



__________________
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote
  #8  
Old 03-30-2001, 11:53 PM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Default Re: word frequency counter

FORGOT TO ATTACH!

__________________
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb