944,079 Members | Top Members by Rank

Ad:
Apr 10th, 2007
0

Dr scheme help -> breaking strings into individual words

Expand Post »
 I need help in Dr scheme. i need to make it so that a string can be broken into the individual words ignoring punctuation. please help
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
captainhair is offline Offline
5 posts
since Apr 2007
Apr 10th, 2007
2

Re: Dr scheme help -> breaking strings into individual words

You really could stand to be more specific. First of all, it's not like anybody's going to just give you the answer. Also, you need to improve your ability to think clearly. You say "ignoring punctuation" as if it's clear what you mean. You can't write clear programs if you don't specify things precisely. In this case, does "ignoring punctuation" mean you want things like "efgh-ijkl" to be treated like one word? Should "foo bar." be split up into ("foo" "bar"), or do you want ("foo" "bar.")?

Suppose you had to do this manually. Pretend you're in an empty room with a desk and some paper. Every 60 seconds, somebody comes in and gives you a slip of paper with a character written on it. It's the next character on the string. How would you split this string up into words? What information do you use to proceed every time you see a new character?
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Apr 11th, 2007
0

Re: Dr scheme help -> breaking strings into individual words

 Sorry should have been more specific. What i mean is taking "Hello World!!" and returning "Hello" "World" ignoring commas, question marks etc...


The way i was thinking it could be done is turning the string into a list and then checking whether the character is like #\space or #\! etc.... Then if is equal to one of those things it jumps to the next character and tests. but if it isnt equal to punctuation then it adds that letter to a new list and once punctuation is reached it creates a new list of characters to turn into a string. The only problem is im not sure if thats the best and easiest way to do it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
captainhair is offline Offline
5 posts
since Apr 2007
Apr 11th, 2007
3

Re: Dr scheme help -> breaking strings into individual words

That's pretty much how it's done. Though instead of checking whether the character is like #\space or #\! as you described, you should check whether the character is not alphabetic. I think that function is called 'CHAR-ALPHABETIC?'.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Apr 11th, 2007
0

Re: Dr scheme help -> breaking strings into individual words

[code]
so far i have gotten it to


(define [extract-alphas text]
(define [alpha-chars chars]
(cond
[(empty? chars)
""]
[(char-alphabetic? (first chars))
(string-append
(string (first chars))
(alpha-chars (rest chars)))]
[else
(string-append
(string (empty) )
(alpha-chars (rest chars)))]))
(alpha-chars (string->list text)))



except it comes back with an error at

[else
(string-append
(string (empty) )
(alpha-chars (rest chars)))]))

What do i need to change to make it work. the else should start a new list after a non-alphabetic character
Last edited by captainhair; Apr 11th, 2007 at 7:57 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
captainhair is offline Offline
5 posts
since Apr 2007
Apr 12th, 2007
1

Re: Dr scheme help -> breaking strings into individual words

What is 'empty'? Is it a function? Are you calling it? I don't remember empty being in the Scheme language standard library. Looking online, it seems like empty is a name for the empty list, the same as '(). So the error would be that you're trying to do a function-call where the 'function' to be called is an empty list value.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005

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 Computer Science Forum Timeline: please send me complete artical about the question
Next Thread in Computer Science Forum Timeline: The smallest laser in the world





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


Follow us on Twitter


© 2011 DaniWeb® LLC