[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Arie Kusuma Atmaja

3/21/2005 10:48:00 AM

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


1 Answer

Robert Klemme

3/21/2005 12:07:00 PM

0


"Arie Kusuma Atmaja" <ariekusumaatmaja@gmail.com> schrieb im Newsbeitrag
news:8c1bd61c05032102481fc4beb2@mail.gmail.com...
> 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