Dr scheme help -> breaking strings into individual words

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Apr 2007
Posts: 5
Reputation: captainhair is an unknown quantity at this point 
Solved Threads: 0
captainhair captainhair is offline Offline
Newbie Poster

Dr scheme help -> breaking strings into individual words

 
0
  #1
Apr 10th, 2007
 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
2
  #2
Apr 10th, 2007
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?
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 5
Reputation: captainhair is an unknown quantity at this point 
Solved Threads: 0
captainhair captainhair is offline Offline
Newbie Poster

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

 
0
  #3
Apr 11th, 2007
 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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
3
  #4
Apr 11th, 2007
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?'.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 5
Reputation: captainhair is an unknown quantity at this point 
Solved Threads: 0
captainhair captainhair is offline Offline
Newbie Poster

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

 
0
  #5
Apr 11th, 2007
[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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
1
  #6
Apr 12th, 2007
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.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC