ドーモ。perlほんやくチーム=サン
瀬野デス。perl勉強中してます。
今回はperlを使ったほんやくを実行します。
怪しげなジャパン語がインプットされているのは仕様です。ご安心を
今回のコードです。
twinkle_trans.pl
#! /usr/bin/env perl use strict; use warnings; my %dict = ( 'twinkle' => 'きらきら', 'little' => 'ちいさな', 'star' => 'ほし', 'how' => 'いかに', 'i' => 'わたし', 'wonder' => 'おどろく', 'what' => 'なに', 'you' => 'あなた', 'are' => 'である', 'up' => 'うえ', 'above' => 'うえに', 'the' => 'その', 'world' => 'せかい', 'so' => 'とても', 'high' => 'たかい', 'like' => 'のよう', 'a' => 'ひとつの', 'diamond' => 'ダイヤモンド', 'in' => 'なかに', 'the' => 'その', 'sky' => 'そら', ); while (<STDIN>) { while (/(\W*)(\w*)/g) { my ($other, $word) = ($1, $2); print $other; if (exists($dict{lc($word)})){ print $dict{lc($word)}; }else{ print $word; } } } print "\n";
このコードに有名なきらきらスターというムジークをインサートします。
twinkle_star.txt
Twinkle, twinkle, little star, How I wonder what you are. Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are.
コマンドイン!した結果です。ご査収ください。
アイエエエエ!?カタコト!?カタコトナンデ!?
…まあ、いうまでもなく順番を考えずに単語だけを一つずつ訳してるだけなので
おかしな日本語になるのは当然の帰結ですね。
そういえば最近のGoogleほんやく㌠は優秀になってきてるとかなんとか。
ITの進歩は目覚ましいですねぇ…
続きはまた次回