OSDN Git Service

のひな 饒平名 姓 # pref3「よへな」では済
[o-dic/o-dic.git] / script / oki2cha.pl
1 #!/usr/bin/perl
2 #
3 # oki2cha.pl - 沖縄辞書のファイルを茶筌で使える形式のテキストに変換する
4 #
5 #               $Id: oki2cha.pl,v 1.3 2003/04/25 06:15:56 void Exp $
6 #
7 # このスクリプトを使って、以下のように「okinawa.dic」を生成してください。
8 #     $ cat ../*.dic | ./oki2cha.pl > okinawa.dic
9 #     $ /usr/local/libexec/chasen/makeint okinawa.dic > okinawa.txt
10 #     $ /usr/local/libexec/chasen/sortdic okinawa.txt > okinawa.int
11 #     $ /usr/local/libexec/chasen/pattool -F okinawa
12 #     $ rm okinawa.txt
13
14 require 5.6.0;
15 use FindBin;
16 use lib $FindBin::Bin;  # For search scripts/ODIC.pm
17 require 'ODIC.pm';
18 use strict;
19 use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
20
21 our $phonate;
22 our $word;
23 our $class;
24
25 my $help_only;
26 my $skip_geta;
27
28 GetOptions(
29     'help|h' => \$help_only,
30     'skip-geta|g' => \$skip_geta
31 );
32 if (defined($help_only)) {
33     print STDERR "usage: $0 [--help|-h] [--skip-geta|-g]\n";
34     exit 1;
35 }
36
37 while (<>) {
38         # JIS X 0208 に含まれていない文字を含む行を読み飛ばす
39         # 読み飛ばしにはコメントに「〓あり」マーカーが必要
40         next if (defined($skip_geta) && /〓あり/);
41
42         next if (/@@@/);        # @@@のある行は読み飛ばす。
43         s/#.*$//;               # `#'以降を取り去る
44         next if (/^\s*$/);      # その結果空行になった行は読み飛ばす。
45         if (/(\S+)\s+(\S+)\s+(\S+)/) {
46                 $phonate = $1;  # 読み
47                 $word    = $2;  # 単語
48                 $class   = $3;  # 品詞
49                 ODIC::check_phonate($phonate);
50                 ODIC::check_word($word);
51                 &convert_class;
52         }
53         else {
54                 print STDERR "Error: $.: too few field number `$_'\n";
55                 print  "$_";
56         }
57 }
58 &version;
59 exit 0;
60
61
62 sub convert_class {
63         if ($class eq "普通名詞") {
64                 print ODIC::to_eucjp("(品詞 (名詞 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
65         }
66         elsif ($class eq "サ変名詞") {
67                 print ODIC::to_eucjp("(品詞 (名詞 サ変接続)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
68         }
69         elsif ($class eq "形動名詞") {
70                 print ODIC::to_eucjp("(品詞 (名詞 形容動詞語幹)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
71         }
72         elsif ($class eq "姓") {
73                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 人名 姓)) ((見出し語 ($word 1000)) (読み $phonate))\n"); 
74         }
75         elsif ($class eq "名") {
76                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 人名 名)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
77         }
78         elsif ($class eq "その他の人名") {
79                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 人名 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
80         }
81         elsif ($class eq "単純地名") {
82                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 地域 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
83         }
84         elsif ($class eq "接尾語付き地名") {
85                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 地域 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
86         }
87         elsif ($class eq "組織名") {
88                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 組織)) ((見出し語 ($word 3000)) (読み $phonate))\n"); 
89         }
90         elsif ($class eq "その他固有名詞") {
91                 print ODIC::to_eucjp("(品詞 (名詞 固有名詞 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
92         }
93         elsif ($class eq "副詞") {
94                 print ODIC::to_eucjp("(品詞 (副詞 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
95         }
96         elsif ($class eq "接続詞") {
97                 print ODIC::to_eucjp("(品詞 (接続詞)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
98         }
99         elsif ($class eq "感動詞") {
100                 print ODIC::to_eucjp("(品詞 (感動詞)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
101         }
102         elsif ($class eq "形容詞") {
103                 print ODIC::to_eucjp("(品詞 (形容詞 自立)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
104         }
105         elsif ($class eq "形容動詞") {
106                 print ODIC::to_eucjp("(品詞 (名詞 形容動詞語幹)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
107         }
108         elsif ($class eq "接頭語") {                 # !!!
109                 print ODIC::to_eucjp("(品詞 (接頭詞 名詞接続)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
110         }
111         elsif ($class eq "数字列接頭語") {
112                 print ODIC::to_eucjp("(品詞 (接頭詞 数接続)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
113         }
114         elsif ($class eq "接尾語") {
115                 print ODIC::to_eucjp("(品詞 (名詞 接尾 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
116         }
117         elsif ($class eq "人名接尾語") {
118                 print ODIC::to_eucjp("(品詞 (名詞 接尾 人名)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
119         }
120         elsif ($class eq "地名接尾語") {
121                 print ODIC::to_eucjp("(品詞 (名詞 接尾 地域)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
122         }
123         elsif ($class eq "組織名接尾語") {
124                 print ODIC::to_eucjp("(品詞 (名詞 接尾 一般)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
125         }
126         elsif ($class eq "数字列接尾語") {
127                 print ODIC::to_eucjp("(品詞 (名詞 接尾 助数詞)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
128         }
129         elsif ($class eq "成句") {
130                 print ODIC::to_eucjp("(品詞 (名詞 引用文字列)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
131         }
132         elsif ($class eq "無品詞") {
133                 print ODIC::to_eucjp("(品詞 (名詞 引用文字列)) ((見出し語 ($word 2000)) (読み $phonate))\n"); 
134         }
135         else {
136                 print STDERR "Error: $.: unknown class `$class': $phonate\t$word\n";
137                 print ODIC::to_eucjp("$phonate,$word,$class\n");
138         }
139 }
140
141
142 sub version {
143         my $sec;
144         my $min;
145         my $hour;
146         my $mday;
147         my $mon;
148         my $year;
149
150         ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
151         $year += 1900;
152         $mon++;
153         print ODIC::to_eucjp("(品詞 (名詞 引用文字列)) ((見出し語 ($year/$mon/$mday沖縄辞書の日付け 2000)) (読み おきなわじしょのひづけ))\n"); 
154 }