Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: Advice on h...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 9 Topic 10978 of 11518
Post > Topic >>

Re: Advice on how to approach character translation

by Jenda@[EMAIL PROTECTED] (Jenda Krynicky) Apr 24, 2008 at 12:50 AM

From: "R (Chandra) Chandrasekhar" <chandra@[EMAIL PROTECTED]
>
> 3. Some transliteration examples are shown below:
> 
> a       a   U+0061   LATIN SMALL LETTER A
> aa      a   U+0101   LATIN SMALL LETTER A WITH MACRON
> A       a   U+0101   LATIN SMALL LETTER A WITH MACRON
> .a      '   U+0027   APOSTROPHE
> ~N         U+1E45   LATIN SMALL LETTER N WITH DOT ABOVE
> RRI        U+1E5D   LATIN SMALL LETTER R WITH DOT BELOW AND MACRON
> R^I	   U+1E5D   LATIN SMALL LETTER R WITH DOT BELOW AND MACRON

Put the transliteration rules into a hash like this:

 %trans =3D (
  'aa' =3D> 'a',
  'A'  =3D> 'a',
  '.a' =3D> "'",
  ...
 );

and build a regexp to match the 1-3 characters to replace:

 @[EMAIL PROTECTED]
 =3D sort {length($b) <=3D> length($a)} keys %trans;
 @[EMAIL PROTECTED]
 =3D map quotemeta($_) @[EMAIL PROTECTED]
 $re =3D join '|', @[EMAIL PROTECTED]
 '.';

and use the regexp to split the text into pieces and transliterate 
them.

 $text =3D~ s/($re)/exists($trans{$1}) ? $trans{$1} : $1/geo;

HTH, Jenda
=3D=3D=3D=3D=3D Jenda@[EMAIL PROTECTED]
 =3D=3D=3D http://Jenda.Krynicky.cz
=3D=3D=
=3D=3D=3D
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery
 




 9 Posts in Topic:
Advice on how to approach character translation
chandra@[EMAIL PROTECTED]  2008-04-23 17:34:22 
Re: Advice on how to approach character translation
Jenda@[EMAIL PROTECTED]   2008-04-24 00:50:48 
Re: Advice on how to approach character translation
chandra@[EMAIL PROTECTED]  2008-04-25 17:41:47 
Re: Advice on how to approach character translation
rvtol+news@[EMAIL PROTECT  2008-04-26 11:41:42 
Re: Advice on how to approach character translation
chandra@[EMAIL PROTECTED]  2008-04-24 23:40:12 
Re: Advice on how to approach character translation
peng.kyo@[EMAIL PROTECTED  2008-04-26 19:39:16 
Re: Advice on how to approach character translation
rvtol+news@[EMAIL PROTECT  2008-04-26 13:54:51 
Re: Advice on how to approach character translation
peng.kyo@[EMAIL PROTECTED  2008-04-26 19:59:08 
Re: Advice on how to approach character translation
rvtol+news@[EMAIL PROTECT  2008-04-26 15:28:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:09:18 CDT 2008.