Lingua::JA::Yomi 日本語読みモジュールをつくった
Posted on 11月 28, 2008
Filed Under japanese, coderepos, perl |
英語を手軽に日本語にしたいと思ってつくった。
今あるモジュールだと、Lingua::JA::Kanaっていうのがあってローマ字→ひらがな変換はできる。
PERL:
-
#!/usr/bin/env perl
-
-
use strict;
-
use warnings;
-
use Lingua::JA::Kana;
-
use utf8;
-
use Encode;
-
-
my $hiragana = romaji2hiragana('aerosmith');
-
# hiragana: あえろsみth
でもローマ字にあてはまらないのは上記のように残念な感じになるので、
Lingua::JA::Yomi ってのをつくった。
http://coderepos.org/share/browser/lang/perl/Lingua-JA-Yomi/trunk
PERL:
-
#!/usr/bin/env perl
-
use strict;
-
use warnings;
-
use utf8;
-
-
use Lingua::JA::Yomi;
-
-
my $converter = new Lingua::JA::Yomi;
-
is( $converter->convert('aerosmith'), 'エアロウスミス','aerosmith');
ルー語インスパイアなので辞書は
Bilingual Emacspeak Project
のを使わせていただいております。
今、あの紫の本を読んでるので、再帰処理で少しずつ変換していくとこを実装するのがたのしかったー
PERL:
-
# pass in utf8 flagged string
-
sub convert {
-
my ($self, $roman, $remainder) = @_;
-
$remainder ||= '';
-
-
-
-
if ( $roman =~ /^([^A-Z]+)(.*)/ ) {
-
# preserve symbols
-
}
-
if ( ! $remainder ) {
-
}
-
else {
-
}
-
}
-
else {
-
}
-
}
perl って何回まで再帰できるんだろ
Comments
Leave a Reply