1.1 はじめに |
こちら
新人研修のネタで、PHPでルー語変換が作れないか、ちょっと考えて半日で作ってみました。
結局、研修には使わなかったのですが。
1.2 しくみ |
http://www.buena-idea.net/~hironobu/Lou/YetAnother-LouTranc.html
このhtmlファイルは、文字列をlou.phpに送り込むだけです。
<html><head> <meta http-equiv="Content-Type" content="text/html;"><title>Yet Another ルー語変換</title> </head><body> <center> <h1 class="center">Yet Another ルー語変換</h1> <form method="post" action="./lou.php"> <textarea name="comment" rows="10" cols="64"></textarea> <br> <input type="submit" value="送信" /> <input type="reset" value="取り消し" /> </p> </form> </center> </body></html> |
<html> <head><meta http-equiv="Content-Type" content="text/html;"> <title>Yet Another ルー語変換</title></head> <body> <?php $fp = fopen("./Lou-dict3", "r"); while(!feof($fp)) { $line = fgets($fp, 256); $line = chop ($line); $list = split(' ', $line); $dict{$list[0]} = $list[1]; } fclose ($fp); ## ## $comment = $HTTP_POST_VARS["comment"]; print "$comment\n"; print "<br>"; print "<hr>"; print "<br>"; foreach ($dict as $key => $val) { $comment = str_replace ($key, $val, $comment); } print "$comment"; ?> <br> <br> <center> <a href="./YetAnother-LouTranc.html">ワンスモア!</a> </center> </body> </html> |
1.3 変換辞書の作り方 |
というか、変換辞書作りのアイディアが浮かんだからPHPでルー語変換をやろうと思った。
http://www.buena-idea.net/~hironobu/Lou/Lou-dict3
http://ftp.monash.edu.au/pub/nihongo/edict.gz
… 2000年対応 [にせんねんたいおう] /(exp) Y2K compliant/ 2000年問題 [にせんねんもんだい] /(n) Y2K bug/year 2000 problem/ 2000年問題対応 [にせんねんもんだいたいおう] /(exp) Y2K compliant/ 2000年問題対策済み [にせんねんもんだいたいさくずみ] /(n) Y2K compliant/ 2等 [にとう] /(n) second class/ 2等軍曹 [にとうぐんそう] /(n) staff sergeant/ 2等車 [にとうしゃ] /(n) second class carriage/ 2等賞 [にとうしょう] /(n) second prize/ 2等親 [にとうしん] /(n) second-degree relative/ … |
… 2000年対応 2000年問題 2000年問題対応 2000年問題対策済み 2等 2等軍曹 2等車 2等賞 2等親 … |
上で作った単語リストをhtmlファイル化します。ただし、一つのhtmlファイルにすると長すぎるので、
10000語程度毎に分割してhtmlファイルにします。
ルー語変換で変換します。