Computer Science Canada Sentence Count |
Author: | sockoo [ Wed May 11, 2005 12:07 pm ] | ||
Post subject: | Sentence Count | ||
Hello All .. This will be my first post soo i'd like to say hi before i actualy ask for help .. i'll try and contribute more to the forums .. but i'v started something new in my class that .. im not to clear on .. ok ok enough of the small talk here's my question: I have to make a word count application which allows the user to enter a sentence and then count and display the number of words entered. Extension - Analyze the paragraph by not only counting the words but by displaying the number of 1 character words, 2 character words, 3 character words this is what i got so far all i need help with is getting the 1..2..3 charcacter words
|
Author: | jamonathin [ Wed May 11, 2005 1:22 pm ] |
Post subject: | |
Since its your first post and you dont know, its ok, but we don't do peoples homework on here, we can give you clues and tips, but we wont write you all of the actual code. Anyways, think of how a sentence is made. Inbetween each word there's a space, unless it's the end of the sentence. Run a for loop for the length(sentence) and have it check where the spaces are, and how far apart, thats how you can find out where the words are. |
Author: | sockoo [ Wed May 11, 2005 7:24 pm ] |
Post subject: | |
Thank you, i didnt want you to write me my code .. what would i learn that way ? .. i just wanted a sorce of direction or help of how to accomplish what i was giving and thanks for the help .. i'll post back with furthur updates or .. if i need any more help |
Author: | Cervantes [ Thu May 12, 2005 3:20 pm ] |
Post subject: | |
If you're not too comfortable with string manipulation, check the tutorial to get some explainations and examples. Ultimately, you don't want to count the number of spaces. The reason is that lots of people (myself included) leave two spaces after the end of my sentances. If you're only searching for spaces, if the user types this way, the output for the number of words will be incorrect. What you actually want to do (I would assume) is search for characters between spaces. |
Author: | sockoo [ Fri May 13, 2005 8:52 am ] | ||
Post subject: | |||
im still not having much luck .. i understand how to find where the space is but .. how would i go about finding .. what many characters are before the space ?
this is what i have but .. im not clear what to do after this obviously i'v found where the space is soo would i find the length of the sentence 1 .. i ? to find out how many charcaters is in the word ? .. and run if statements 1 .. 3 to find if it has 1 charc 2 charcs or 3 and so on ? .. |
Author: | jamonathin [ Sun May 15, 2005 7:30 pm ] | ||
Post subject: | |||
Here's the answer you want. I'm guessing you dont have it by now since you haven't posted it.
|
Author: | sockoo [ Sun May 15, 2005 7:35 pm ] |
Post subject: | |
hmm thanks for the help but that isnt quiet what i was trying to ahieve ... lets say the user enters " Keep It Simple Stupid " sentence length: 22 (with spaces) 4 charc words: 1 2 charc words: 1 6 charc words: 2 |
Author: | MysticVegeta [ Mon May 16, 2005 7:03 am ] |
Post subject: | |
Check the Cervantes link, He has a part in the tut that gives how you can separate the words, and then you can go -> if length(seperateword) = 2 then put 2 end if Since i cant post the code, i will ask yu to check it out http://www.compsci.ca/v2/viewtopic.php?t=8229 |
Author: | jamonathin [ Mon May 16, 2005 7:48 am ] |
Post subject: | |
Oh yeah I forgot about that tutorial, definately check it out, it has everything you need to know. |
Author: | sockoo [ Mon May 16, 2005 9:10 am ] |
Post subject: | |
i'v read that tutorial over about 5 times ... but i'll re read it when i get home .. and go from there . thanks for the help guys |
Author: | Notoroge [ Mon May 16, 2005 2:34 pm ] | ||
Post subject: | |||
It's not elegant; and probably the dirtiest way to do it, but it took me ten minutes to make and it works. Update: It does crash when you put two or more spaces consecutively. This is only to point you in the right direction though. Kinda the concept of what you have to do. Fix it however you want. |
Author: | Notoroge [ Mon May 16, 2005 2:46 pm ] | ||
Post subject: | |||
jamonathin, I just thought of something. Instead of trapping for most commonly used punctuation notes, why not do something like,
|
Author: | Token [ Mon May 16, 2005 3:28 pm ] |
Post subject: | |
hmm i just got an idea, why not export the sentence to a text file and then bring it in one word at a time, that way you could ealsily count the words, and as each word is in the temporary variable that you set up it could count the number of letters. if u dont understand what i'm saying or u need help let me kno |
Author: | sockoo [ Mon May 16, 2005 4:58 pm ] |
Post subject: | |
Notorage , Omg! , u'v made my program to a dot .. everything it was suppose to be .. except i learned nothing from it .. even tho it was nice of you .. i would of rather a source of direction how to do it .. rather then u just giving me the answer .. but thank you ! , now gotta read through ur code and make sure i understand everything you did and would be able to do it my self .. if needed in the furture! |
Author: | Notoroge [ Mon May 16, 2005 5:03 pm ] |
Post subject: | |
I wanted to see if I could do it. I also purposefully left out any documentation and didn't bother to clean up the code or error-trap. Because I figured I'd might aswell make you read through everything, understand it, and clean it up yourself. |
Author: | Cervantes [ Tue May 17, 2005 4:52 pm ] | ||
Post subject: | |||
Token: that takes far too much resources. A word count really should not have to access a file. It is a neat idea, though inefficient. Here's a function that uses the boolean variable idea I was talking about earlier (was it this thread?):
This was a progression from someone's code above, so that would explain some of the same comments/variable names. Anywho, I hope you follow that. |
Author: | Token [ Tue May 17, 2005 5:07 pm ] | ||
Post subject: | |||
umm actually it is pretty simple, a lot simpler than your idea. only 20 lines of code, and it deletes the resource file automaticly.
|
Author: | Cervantes [ Tue May 17, 2005 6:09 pm ] |
Post subject: | |
No, you're missing the point. I'm not saying it isn't easier to code, I'm saying it's inefficient. There's no need to open a file, write stuff into it, then read it back. The only reason to write to files is to store data. You're not storing data, given that you are deleting the file a few lines later. Do you think Microsoft Word takes the data the user has entered and sends it off to a .txt (or better yet, a .doc!) and then retrevies it all back just to get a word count? That takes far too many resources, given the simple nature of the task. Oh, and my code was also twenty lines. |
Author: | Token [ Tue May 17, 2005 7:42 pm ] | ||
Post subject: | |||
but it is so much simpler to add the counting of the letters of the words, look.
whereas yours you would have to wright a whole new section of code or even a new function to return those values. and what is the problem with creating a text file and deleting it? it works the same as your program. and of corse microsoft word doesnt, but it isnt written in turing |
Author: | Cervantes [ Tue May 17, 2005 8:18 pm ] |
Post subject: | |
Token wrote: but it is so much simpler to add the counting of the letters of the words, look.
You need to understand the difference between "simple" and "good". They do not always go hand in hand. Token wrote: whereas yours you would have to wright a whole new section of code or even a new function to return those values. I could just have my function return an array of values. Token wrote: and what is the problem with creating a text file and deleting it? it works the same as your program. The output may be correct, but the steps you take to get that output are wrong. Remember that this is simply a tidbit of code to count words. If we were making a word processor, there would be so many other things like this. For example, counting lines, counting total characters (with and without spaces), counting paragraphs, counting pages, etc. I realize that with some of these you couldn't use the file techneque, but the point still stands: your code would become grotesque as you constantly create and delete files just to determine this information. Token wrote: and of corse microsoft word doesnt, but it isnt written in turing That makes absolutely no difference. |
Author: | jamonathin [ Wed May 18, 2005 7:51 am ] |
Post subject: | |
I'd quit token, lol. You won't win. |
Author: | Notoroge [ Wed May 18, 2005 7:56 am ] |
Post subject: | |
Just for the sake of argument, I think what he was getting at is that this is a simple Turing program for school that will never be required to process the complexity of information that a word-processor does, and thus in this case it's efficient enough to get by and simple. I agree with you in that to count the words by doing this method for OO.o or MS-WORD, it would be rediculous to do so. But for the task at hand, it's good enough. |
Author: | Token [ Wed May 18, 2005 11:21 am ] |
Post subject: | |
yay some support lol, thats exactly what i was saying we arent building a full word processor here just somthing used to analyse a sentence. and turing is a very basic language so its hard to do some of the things that you could do in C++ or whatever msword was created in. the only reason i feel this is better is because you can add so many options easily. also its all in oppinion what is 'good' its not like one takes drastically more time than the other so i dont see a problem with my code. |