root/lang/scheme/gauche/bindings/mecab/trunk/test-dep-ipadic.scm

Revision 131, 15.7 kB (checked in by naoya_t, 15 years ago)

=> http://cvs.sourceforge.jp/view/gauche/Gauche-mecab/

Line 
1;; -*- coding:euc-jp -*-
2;;
3;; dictionary-dependent tests for mecab module <vol.2>
4;;
5;;  using mecab-0.98pre1 <default:EUC-JP>
6;;      + mecab-ipadic-2.7.0-20070801 <utf-8>
7;;
8;;  written by naoya_t
9
10(use gauche.test)
11
12(test-start "mecab: dictionary-dependent tests <vol.2>: ipadic")
13(use text.mecab)
14(test-module 'text.mecab)
15
16(let1 m (mecab-new2 "")
17  (test-section "mecab-sparse-tostr")
18  (test* "��Ĥ���"
19         (string-join '("������,*,*,*,*,�������                        "��\t���ʽ���,*,*,*,��,��,��"
20                        "���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������"
21                        "��\t�����,*,*,*,*,��,��,��"
22                        "EOS"
23                        "") "\n")
24         (mecab-sparse-tostr m "��Ĥ���"))
25
26  (test-section "mecab-sparse-tostr2")
27  (test* "\"��Ĥ���\", len=6"
28         (string-join '("������,*,*,*,*,�������                        "��\t���ʽ���,*,*,*,��,��,��"
29                        "EOS"
30                        "") "\n")
31         (mecab-sparse-tostr2 m "��Ĥ���" 6))
32
33  (test-section "mecab-sparse-tonode, mecab-node-***")
34  (let1 node (mecab-sparse-tonode m "��Ĥ���")
35    (test* "mecab-node?" #t (mecab-node? node))
36    (test* "no previous node" #f (mecab-node-prev node))
37    (test* "next node" #t (mecab-node? (mecab-node-next node)))
38    (test* "enext" #f (mecab-node? (mecab-node-enext node)))
39    (test* "bnext" #f (mecab-node? (mecab-node-bnext node)))
40    (test* "surface" "" (mecab-node-surface node))
41    (test* "feature" "BOS/EOS,*,*,*,*,*,*,*,*" (mecab-node-feature node))
42    (test* "length" 0 (mecab-node-length node))
43    (test* "rlength" 0 (mecab-node-rlength node))
44    (test* "id" 0 (mecab-node-id node))
45    (test* "rc-attr" 0 (mecab-node-rc-attr node))
46    (test* "lc-attr" 0 (mecab-node-lc-attr node))
47    (test* "posid" 0 (mecab-node-posid node))
48    (test* "char-type" 0 (mecab-node-char-type node))
49    (test* "stat" 'mecab-bos-node (mecab-node-stat node))
50    (test* "best?" #t (mecab-node-best? node))
51    (test* "alpha" 0.0 (mecab-node-alpha node))
52    (test* "beta" 0.0 (mecab-node-beta node))
53    (test* "prob" 0.0 (mecab-node-prob node))
54    (test* "wcost" 0 (mecab-node-wcost node))
55    (test* "cost" 0 (mecab-node-cost node))
56
57    (set! node (mecab-node-next node))
58    (test* "mecab-node?" #t (mecab-node? node))
59    (test* "previous node" #t (mecab-node? (mecab-node-prev node)))
60    (test* "next node" #t (mecab-node? (mecab-node-next node)))
61    (test* "enext" #t (mecab-node? (mecab-node-enext node)))
62    (test* "bnext" #f (mecab-node? (mecab-node-bnext node)))
63    (test* "surface" "��mecab-node-surface node))
64    (test* "feature" "̾���,*,*,*,*,�������(mecab-node-feature node))
65    (test* "length" 3 (mecab-node-length node))
66    (test* "rlength" 3 (mecab-node-rlength node))
67    (test* "id" 1 (mecab-node-id node))
68    (test* "rc-attr" 1285 (mecab-node-rc-attr node))
69    (test* "lc-attr" 1285 (mecab-node-lc-attr node))
70    (test* "posid" 38 (mecab-node-posid node))
71    (test* "char-type" 2 (mecab-node-char-type node))
72    (test* "stat" 'mecab-nor-node (mecab-node-stat node))
73    (test* "best?" #t (mecab-node-best? node))
74    (test* "alpha" 0.0 (mecab-node-alpha node))
75    (test* "beta" 0.0 (mecab-node-beta node))
76    (test* "prob" 0.0 (mecab-node-prob node))
77    (test* "wcost" 7439 (mecab-node-wcost node))
78    (test* "cost" 7156 (mecab-node-cost node))
79    )
80
81  (test-section "mecab-sparse-tonode2")
82  (let1 node (mecab-sparse-tonode2 m "��Ĥ���" 6)
83    (test* "mecab-node?" #t (mecab-node? node))
84    (test* "feature" "BOS/EOS,*,*,*,*,*,*,*,*" (mecab-node-feature node))
85    (test* "stat" 'mecab-bos-node (mecab-node-stat node))
86
87    (set! node (mecab-node-next node))
88    (test* "mecab-node?" #t (mecab-node? node))
89    (test* "surface" "��mecab-node-surface node))
90    (test* "feature" "̾���,*,*,*,*,�������(mecab-node-feature node))
91    (test* "stat" 'mecab-nor-node (mecab-node-stat node))
92
93    (set! node (mecab-node-next node))
94    (test* "mecab-node?" #t (mecab-node? node))
95    (test* "surface" "��" (mecab-node-surface node))
96    (test* "feature" "���ʽ���,*,*,*,��,��,��" (mecab-node-feature node))
97    (test* "stat" 'mecab-nor-node (mecab-node-stat node))
98
99    (set! node (mecab-node-next node))
100    (test* "mecab-node?" #t (mecab-node? node))
101    (test* "feature" "BOS/EOS,*,*,*,*,*,*,*,*" (mecab-node-feature node))
102    (test* "stat" 'mecab-eos-node (mecab-node-stat node))
103    (test* "no next node" #f (mecab-node-next node))
104    )
105;  (test-section "mecab-format-node")
106;  (let1 node (mecab-sparse-tonode m "��Ĥ���")
107;   (test* "BOS" "" (mecab-format-node mecab node)))
108  (mecab-destroy m))
109
110(let ([m (mecab-new2 "-l 1")] ;;
111      [input "��Ĥ���"])
112  (test-section "mecab-nbest-sparse-tostr")
113  (test* #`",|input|, N=1"
114         "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
115         (mecab-nbest-sparse-tostr m 1 input))
116  (test* #`",|input|, N=2"
117         (string-append
118          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
119          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
120          )
121         (mecab-nbest-sparse-tostr m 2 input))
122  (test* #`",|input|, N=3"
123         (string-append
124          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
125          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
126          "������,*,*,*,*,����,����\n��\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
127          )
128         (mecab-nbest-sparse-tostr m 3 input))
129
130  (test-section "mecab-nbest-sparse-tostr2")
131  (test* #`",|input|, N=1"
132         "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
133         (mecab-nbest-sparse-tostr2 m 1 input 6))
134  (test* #`",|input|, N=2"
135         (string-append
136          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
137          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
138          )
139         (mecab-nbest-sparse-tostr2 m 2 input 6))
140  (test* #`",|input|, N=3"
141         (string-append
142          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
143          "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
144          "������,*,*,*,*,����,����\n��\t���ʽ���,*,*,*,��,��,��\nEOS\n"
145          )
146         (mecab-nbest-sparse-tostr2 m 3 input 6))
147
148  (test-section "mecab-nbest-init")
149  (test* "init" 1 (mecab-nbest-init m input))
150  (test-section "mecab-nbest-next-tostr")
151  (test* "#1"
152        "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
153        (mecab-nbest-next-tostr m))
154  (test* "#2"
155        "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
156        (mecab-nbest-next-tostr m))
157  (test* "#3"
158        "������,*,*,*,*,����,����\n��\t���ʽ���,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
159        (mecab-nbest-next-tostr m))
160  (test* "#4"
161         "������,*,*,*,*,���������\t���³��*,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
162         (mecab-nbest-next-tostr m))
163  (test* "#5"
164         "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n�\t��ƻ��Ω,*,*,��ƻ졦�������,����³,���,����,����\n��\tư����,*,*,��,Ϣ��������,��\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
165         (mecab-nbest-next-tostr m))
166  (test* "#6"
167         "������,*,*,*,*,���������\t���³��*,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
168         (mecab-nbest-next-tostr m))
169  (test* "#7"
170         "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\n�\t��ƻ��Ω,*,*,��ƻ졦�������,����³,���,����,����\n��\tư����,*,*,��,Ϣ��������,��\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
171         (mecab-nbest-next-tostr m))
172  (test* "#8"
173         "������,*,*,*,*,���������\t�³��,*,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
174         (mecab-nbest-next-tostr m))
175  (test* "#9"
176         "������,*,*,*,*,����,����\n��\t���³��*,*,*,*,��,��,��\n���\t��ƻ��Ω,*,*,��ƻ졦�������,������,������,������\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
177         (mecab-nbest-next-tostr m))
178  (test* "#10"
179         "������,*,*,*,*,����,����\n��\t���ʽ���,*,*,*,��,��,��\n�\t��ƻ��Ω,*,*,��ƻ졦�������,����³,���,����,����\n��\tư����,*,*,��,Ϣ��������,��\n��\t�����,*,*,*,*,��,��,��\nEOS\n"
180         (mecab-nbest-next-tostr m))
181  (dotimes (i 733)
182    (mecab-nbest-next-tostr m))
183  (test* "#744"
184         "������,*,*,*,*,����,����\n��\tư����,��ʡ���,�������죲,�����,��\n�\t̾����̾��ϰ��,*,*,,����,����\n��\tư����,*,*,��,̤��������,��\n��\t̾�����³,*,*,*,*,*\nEOS\n"
185         (mecab-nbest-next-tostr m))
186  ;; no more results...
187  (test* "#745" #f (mecab-nbest-next-tostr m))
188  (test* "mecab-strerror" #f (string=? "" (mecab-strerror m)))
189 
190  (test-section "mecab-nbest-init2")
191  (test* "init2" 1 (mecab-nbest-init2 m input 6))
192  (test* "#1"
193        "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
194        (mecab-nbest-next-tostr m))
195  (test* "#2"
196        "������,*,*,*,*,���������\t���ʽ���,*,*,*,��,��,��\nEOS\n"
197        (mecab-nbest-next-tostr m))
198  (test* "#3"
199        "������,*,*,*,*,����,����\n��\t���ʽ���,*,*,*,��,��,��\nEOS\n"
200        (mecab-nbest-next-tostr m))
201  (dotimes (i 8) (mecab-nbest-next-tostr m))
202  (test* "#12"
203         "������,*,*,*,*,����,����\n��\tư����,��ʡ���,�������죲,�����,��\nEOS\n"
204         (mecab-nbest-next-tostr m))
205  ;; no more results...
206  (test* "#13" #f (mecab-nbest-next-tostr m))
207  (test* "mecab-strerror" #f (string=? "" (mecab-strerror m)))
208
209  (test-section "mecab-nbest-next-tonode")
210  (mecab-nbest-init m input)
211  (test* "#1" #t (mecab-node? (mecab-nbest-next-tonode m)))
212  (dotimes (i 742) (mecab-nbest-next-tonode m))
213  (test* "#744" #t (mecab-node? (mecab-nbest-next-tonode m))); EOS
214  ;; no more results...
215  (test* "#745" #f (mecab-node? (mecab-nbest-next-tonode m)))
216  (test* "mecab-strerror" #f (string=? "" (mecab-strerror m)))
217
218  (mecab-destroy m))
219
220;;
221;; these values below may differ !!!
222(test-section "mecab-dictionary-info, mecab-dictionary-info-***")
223(let* ([m (mecab-new2 "")]
224       [dinfo (mecab-dictionary-info m)])
225  (test* "mecab-dictionary-info?" #t (mecab-dictionary-info? dinfo))
226  (test* "mecab-dictionary-info-filename"
227         "/usr/local/lib/mecab/dic/ipadic/sys.dic" (mecab-dictionary-info-filename dinfo))
228  (test* "mecab-dictionary-info-charset"
229         "utf8" (mecab-dictionary-info-charset dinfo))
230  (test* "mecab-dictionary-info-size"
231         392126 (mecab-dictionary-info-size dinfo))
232  (test* "mecab-dictionary-info-type" 'mecab-sys-dic (mecab-dictionary-info-type dinfo))
233  (test* "mecab-dictionary-info-lsize"
234         1316 (mecab-dictionary-info-lsize dinfo))
235  (test* "mecab-dictionary-info-rsize"
236         1316 (mecab-dictionary-info-rsize dinfo))
237  (test* "mecab-dictionary-info-version"
238         102 (mecab-dictionary-info-version dinfo))
239;  (let1 next-dinfo (mecab-dictionary-info-next dinfo)
240;    (test* "has next?" #t (mecab-dictionary-info? next-dinfo)))
241  (mecab-destroy m))
242
243
244;;;;;;;;;;
245;;
246;; TO DO
247;;
248;;(test-section "mecab-do")
249;;(test-section "mecab-dict-index")
250;;(test-section "mecab-dict-gen")
251;;(test-section "mecab-cost-train")
252;;(test-section "mecab-system-eval")
253;;(test-section "mecab-test-gen")
254
255;;;
256;;; tagger (message passing)
257;;;
258(test-section "tagger")
259(let1 tagger (mecab-tagger "-l 1")
260  (test* "tagger'parse-to-string"
261         (string-join '("���\t̾���ǽ,*,*,*,*,���,���祦,���硼"
262                        "��������*,*,*,*,����                        "��\tư���Ω,*,*,������������������,��"
263                        "�ʤ�\t���,*,*,��졦�ʥ�,����ʤ�,�ʥ�,�ʥ�"
264                        "��t���³��*,*,*,*,������
265                        "��t������*,*,*,*,������
266                        "EOS"
267                        "") "\n")
268         ([tagger'parse-to-string] "����⤷�ʤ��Ȥ�))
269
270  (let1 node ([tagger'parse-to-node] "����⤷�ʤ��Ȥ�)
271    (test* "mecab-node?" #t (mecab-node? node))
272    (test* "mecab-node-surface" "" (mecab-node-surface node))
273    (test* "mecab-node-feature" "BOS/EOS,*,*,*,*,*,*,*,*" (mecab-node-feature node))
274    (test* "mecab-node-cost" 0 (mecab-node-cost node))
275
276    (set! node (mecab-node-next node))
277    (test* "mecab-node?" #t (mecab-node? node))
278    (test* "mecab-node-surface" "���" (mecab-node-surface node))
279    (test* "mecab-node-feature" "̾���ǽ,*,*,*,*,���,���祦,���硼" (mecab-node-feature node))
280    (test* "mecab-node-cost" 3947 (mecab-node-cost node))
281    ;;(test* "format-node" "" ([tagger'format-node] node))
282
283    (set! node (mecab-node-next node))
284    (test* "mecab-node?" #t (mecab-node? node))
285    (test* "mecab-node-surface" "��(mecab-node-surface node))
286    (test* "mecab-node-feature" "������*,*,*,*,����(mecab-node-feature node))
287    (test* "mecab-node-cost" 5553 (mecab-node-cost node))
288
289    (set! node (mecab-node-next node))
290    (test* "mecab-node?" #t (mecab-node? node))
291    (test* "mecab-node-surface" "��" (mecab-node-surface node))
292    (test* "mecab-node-feature" "ư���Ω,*,*,������������������,��" (mecab-node-feature node))
293    (test* "mecab-node-cost" 11566 (mecab-node-cost node))
294
295    (set! node (mecab-node-next node))
296    (test* "mecab-node?" #t (mecab-node? node))
297    (test* "mecab-node-surface" "�ʤ�" (mecab-node-surface node))
298    (test* "mecab-node-feature" "���,*,*,��졦�ʥ�,����ʤ�,�ʥ�,�ʥ�" (mecab-node-feature node))
299    (test* "mecab-node-cost" 3601 (mecab-node-cost node))
300
301    (set! node (mecab-node-next node))
302    (test* "mecab-node?" #t (mecab-node? node))
303    (test* "mecab-node-surface" "�� (mecab-node-surface node))
304    (test* "mecab-node-feature" "���³��*,*,*,*,������ (mecab-node-feature node))
305    (test* "mecab-node-cost" 4716 (mecab-node-cost node))
306
307    (set! node (mecab-node-next node))
308    (test* "mecab-node?" #t (mecab-node? node))
309    (test* "mecab-node-surface" "�� (mecab-node-surface node))
310    (test* "mecab-node-feature" "������*,*,*,*,������ (mecab-node-feature node))
311    (test* "mecab-node-cost" 10676 (mecab-node-cost node))
312
313    (set! node (mecab-node-next node))
314    (test* "mecab-node?" #t (mecab-node? node))
315    (test* "mecab-node-surface" "" (mecab-node-surface node))
316    (test* "mecab-node-feature" "BOS/EOS,*,*,*,*,*,*,*,*" (mecab-node-feature node))
317    (test* "mecab-node-cost" 8292 (mecab-node-cost node))
318
319    (set! node (mecab-node-next node))
320    (test* "mecab-node?" #f (mecab-node? node))
321
322    (tagger'destroy)
323    ))
324
325(test-end)
Note: See TracBrowser for help on using the browser.