Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > squeeze - Should I have words' database to make it right?

Reply
Thread Tools

squeeze - Should I have words' database to make it right?

 
 
Arie Kusuma Atmaja
Guest
Posts: n/a
 
      03-21-2005
s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'
puts s.squeeze # right, means 'where r
u going?' (Indonesian)

indoscripts = 'Tq, canggihhh meeeennnn.......'
puts indoscripts.squeeze # should be canggih,
not cangih (Indonesian)

milis = 'Scholarships often go abegging'
puts milis.squeeze # should be abegging,
not abeging (English)

french = %Q/Salut! Je m'appelle Arie. Ruby tous les jours /
puts french.squeeze # should be Je
m'appelle, not m'apele

Should I have words' database to make it right?

--

Best Regards,
Arie Kusuma Atmaja


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      03-21-2005

"Arie Kusuma Atmaja" <> schrieb im Newsbeitrag
news:...
> s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'
> puts s.squeeze # right, means 'where r
> u going?' (Indonesian)
>
> indoscripts = 'Tq, canggihhh meeeennnn.......'
> puts indoscripts.squeeze # should be canggih,
> not cangih (Indonesian)
>
> milis = 'Scholarships often go abegging'
> puts milis.squeeze # should be abegging,
> not abeging (English)
>
> french = %Q/Salut! Je m'appelle Arie. Ruby tous les jours /
> puts french.squeeze # should be Je
> m'appelle, not m'apele
>
> Should I have words' database to make it right?


As this is obviously a language depedent feature that's certainly the best
approach. You might get away with doing this:

# replace sequences of three or more subsequent characters
s.gsub(/(\w)\1{2,}/, '\\1')

>> s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'

=> "Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?"
>> s.gsub(/(\w)\1{2,}/, '\\1')

=> "Hei mauu kemana?"

>> s = 'Scholarships often go abegging'

=> "Scholarships often go abegging"
>> s.gsub(/(\w)\1{2,}/, '\\1')

=> "Scholarships often go abegging"

You might as well anchor at word end if that helps:

>> s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'

=> "Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?"
>> s.gsub(/(\w)\1+\b/, '\\1')

=> "Hei mau kemannnna?"

Kind regards

robert

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Feds put squeeze on Internet firms Imhotep Computer Security 0 05-31-2006 05:28 AM
Can I squeeze this down any more please? Big Bill HTML 7 05-07-2004 07:27 PM
squeeze and package imports Mathias Waack Python 2 09-27-2003 08:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57