Show
Ignore:
Timestamp:
04/15/09 09:41:07 (16 years ago)
Author:
naoya_t
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/scheme/gauche/bindings/mecab/trunk/test.scm

    r117 r131  
    11;; -*- coding:euc-jp -*- 
    22;; 
    3 ;; test for mecab module 
     3;; dictionary-independent tests for mecab module 
    44;; 
    55 
    66(use gauche.test) 
    77 
    8 (test-start "mecab") 
     8(test-start "mecab: dictionary-independent tests") 
    99(use text.mecab) 
    1010(test-module 'text.mecab) 
    1111 
    12 (define m (mecab-new2 "")) 
    13 (test* "mecab-new2" #t (is-a? m <mecab>)) 
    14 (test* "mecab-destroy" #f (mecab-destroyed? m)) 
    15 (mecab-destroy m) 
    16 (test* "mecab-destroy" #t (mecab-destroyed? m)) 
     12;; 
     13;; write-object / ctor 
     14;; 
     15(define-macro (displayed-string obj) 
     16  `(with-output-to-string (lambda () (display ,obj)))) 
    1717 
    18 (test* "mecab-sparse-tostr" #f 
    19        (mecab-sparse-tostr m "�Ϻ�ϼ�Ϻ���������Ҥ�Ϥ�����")) 
    20 (test* "mecab-strerror" #t (string? (mecab-strerror m))) 
     18(test-section "write-object (display)") 
     19(let1 m (mecab-new '()) 
     20  (test* "(mecab-new '())" "#<mecab ()>" (displayed-string m)) 
     21  (mecab-destroy m)) 
     22(let1 m (mecab-new '("-O" "chasen")) 
     23  (test* "(mecab-new '(\"-O\" \"chasen\"))" "#<mecab ((output-format-type chasen))>" (displayed-string m)) 
     24  (mecab-destroy m)) 
     25(let1 m (mecab-new2 "") 
     26  (test* "(mecab-new2 \"\")" "#<mecab ()>" (displayed-string m)) 
     27  (mecab-destroy m)) 
     28(let1 m (mecab-new2 "-Ochasen") 
     29  (test* "(mecab-new2 \"-Ochasen\")" "#<mecab ((output-format-type chasen))>" (displayed-string m)) 
     30  (mecab-destroy m)) 
     31(let1 m (mecab-new2 "-O chasen") 
     32  (test* "(mecab-new2 \"-O chasen\")" "#<mecab ((output-format-type chasen))>" (displayed-string m)) 
     33  (mecab-destroy m)) 
    2134 
    22 (define m (mecab-new2 "")) 
    23 (test* "mecab-sparse-tostr" 
    24        "�Ϻ      ̾����,*,*,�Ϻ,ï¿½ï¿½ï¿½í¤¦,*\n\ 
    25         �������*,*,����*\n\ 
    26         ��Ϻ     Ì¾ï¿½ï¿½ï¿½ï¿½,*,*,��Ϻ,ï¿½ï¿½ï¿½í¤¦,*\n\ 
    27         ��      ���ʽ�*,*,��,��,*\n\ 
    28         ��ư��,�Ҳ�ư�쥿���������Ʒ����ä��ɽɽ��:�� 
    29         �������������,���ư�����������\n\ 
    30         �       Ì¾ï¿½ï¿½ï¿½Ì¾ï¿½ï¿½,*,�,�ۤ���:�� �ɽɽ��:�\n\ 
    31         ����ʽ�*,*,��,*\n\ 
    32         �ֻ�̾����,*,*,�ֻ��Ϥʤ�,*\n\ 
    33         �����ʽ�*,*,����*\n\ 
    34         �����   Æ°ï¿½ï¿½,�Ҳ�ư�쥵���������,�錄����,�°ư����ʴ���ɽɽ��:���\n\ 
    35         ��      ����,*,*,��,��,*\n\ 
    36         EOS\n" 
    37        (mecab-sparse-tostr m "�Ϻ�ϼ�Ϻ���������Ҥ�Ϥ�����")) 
    38                              
    39 (mecab-destroy m) 
     35(test-section "reader-ctor") 
     36(let1 m #,(mecab "") ;; with reader-ctor 
     37  (test* "#,(mecab \"\") : mecab?" #t (mecab? m)) 
     38  (test* "#,(mecab \"\") : options" '() (mecab-options m)) 
     39  (mecab-destroy m)) 
     40(let1 m #,(mecab "-Ochasen") ;; with reader-ctor 
     41  (test* "#,(mecab \"-Ochasen\") : mecab?" #t (mecab? m)) 
     42  (test* "#,(mecab \"-Ochasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     43  (mecab-destroy m)) 
     44(let1 m #,(mecab :O chasen :l 1) ;; with reader-ctor 
     45  (test* "#,(mecab :O chasen :l 1) : mecab?" #t (mecab? m)) 
     46  (test* "#,(mecab :O chasen :l 1) : mecab-options" '((output-format-type chasen) (lattice-level 1)) (mecab-options m)) 
     47  (mecab-destroy m)) 
     48 
     49;; 
     50;; mecab?, mecab-node?, mecab-dictionary-info? 
     51;; 
     52(let* ([m (mecab-new2 "")] 
     53       [node (mecab-sparse-tonode m "")] 
     54       [dinfo (mecab-dictionary-info m)]) 
     55  (test-section "mecab?, mecab-node?, mecab-dictionary-info?") 
     56 
     57  (test* "is-a? m <mecab>" #t (is-a? m <mecab>)) 
     58  (test* "is-a? node <mecab>" #t (is-a? node <mecab-node>)) 
     59  (test* "is-a? dinfo <mecab>" #t (is-a? dinfo <mecab-dictionary-info>)) 
     60 
     61  (test* "mecab? m" #t (mecab? m)) 
     62  (test* "mecab? node" #f (mecab? node)) 
     63  (test* "mecab? dinfo" #f (mecab? dinfo)) 
     64 
     65  (test* "mecab-node? m" #f (mecab-node? m)) 
     66  (test* "mecab-node? node" #t (mecab-node? node)) 
     67  (test* "mecab-node? dinfo" #f (mecab-node? dinfo)) 
     68 
     69  (test* "mecab-dictionary-info? m" #f (mecab-dictionary-info? m)) 
     70  (test* "mecab-dictionary-info? node" #f (mecab-dictionary-info? node)) 
     71  (test* "mecab-dictionary-info? dinfo" #t (mecab-dictionary-info? dinfo)) 
     72 
     73  (mecab-destroy m)) 
     74 
     75;; mecab, mecab-options 
     76(test-section "mecab-options") 
     77(let1 m (mecab-new '()) 
     78  (test* "(mecab-new '())" '() (mecab-options m)) 
     79  (mecab-destroy m)) 
     80(let1 m (mecab-new '("-O" "chasen")) 
     81  (test* "(mecab-new '(\"-O\" \"chasen\"))" '((output-format-type chasen)) (mecab-options m)) 
     82  (mecab-destroy m)) 
     83(let1 m (mecab-new2 "") 
     84  (test* "(mecab-new2 \"\"" '() (mecab-options m)) 
     85  (mecab-destroy m)) 
     86(let1 m (mecab-new2 "-Ochasen") 
     87  (test* "mecab?" #t (mecab? m)) 
     88  (test* "(mecab-new2 \"-Ochasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     89  (mecab-destroy m)) 
     90(let1 m (mecab-new2 "-O chasen") 
     91  (test* "mecab?" #t (mecab? m)) 
     92  (test* "(mecab-new2 \"-O chasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     93  (mecab-destroy m)) 
     94(let1 m (mecab-new2 "--output-format-type chasen") 
     95  (test* "mecab?" #t (mecab? m)) 
     96  (test* "(mecab-new2 \"--output-format-type chasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     97  (mecab-destroy m)) 
     98(let1 m (mecab-new2 "--output-format-type=chasen") 
     99  (test* "mecab?" #t (mecab? m)) 
     100  (test* "(mecab-new2 \"--output-format-type=chasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     101  (mecab-destroy m)) 
     102(let1 m (mecab "") 
     103  (test* "(mecab \"\") : mecab?" #t (mecab? m)) 
     104  (test* "(mecab \"\") : options" '() (mecab-options m)) 
     105  (mecab-destroy m)) 
     106(let1 m (mecab "-Ochasen") 
     107  (test* "(mecab \"-Ochasen\") : mecab?" #t (mecab? m)) 
     108  (test* "(mecab \"-Ochasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     109  (mecab-destroy m)) 
     110(let1 m (mecab "-O chasen") 
     111  (test* "(mecab \"-O chasen\") : mecab?" #t (mecab? m)) 
     112  (test* "(mecab \"-O chasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     113  (mecab-destroy m)) 
     114(let1 m (mecab "-O" "chasen") 
     115  (test* "(mecab \"-O\" \"chasen\") : mecab?" #t (mecab? m)) 
     116  (test* "(mecab \"-O\" \"chasen\") : options" '((output-format-type chasen)) (mecab-options m)) 
     117  (mecab-destroy m)) 
     118(let1 m (mecab :O 'chasen :l 1) 
     119  (test* "(mecab :O chasen :l 1) : mecab?" #t (mecab? m)) 
     120  (test* "(mecab :O chasen :l 1) : mecab-options" '((output-format-type chasen) (lattice-level 1)) (mecab-options m)) 
     121  (mecab-destroy m)) 
     122 
     123;; 
     124;; APIs 
     125;; 
     126(test-section "mecab-new") 
     127(let1 m (mecab-new '()) 
     128  (test* "is-a? <mecab>" #t (is-a? m <mecab>)) 
     129  (test* "mecab?" #t (mecab? m)) 
     130 
     131  (test-section "mecab-destroy") 
     132  (test* "not destroyed yet" #f (mecab-destroyed? m)) 
     133  (mecab-destroy m) 
     134  (test* "destroyed" #t (mecab-destroyed? m)) 
     135  ) 
     136 
     137(test-section "mecab-new2") 
     138(let1 m (mecab-new2 "") 
     139  (test* "is-a? <mecab>" #t (is-a? m <mecab>)) 
     140  (test* "mecab?" #t (mecab? m)) 
     141  (test* "options" '() (mecab-options m)) 
     142  (mecab-destroy m)) 
     143 
     144(test-section "mecab-version") 
     145(test* "mecab-version" 1 
     146       (rxmatch-num-matches 
     147        (#/^[0-9]+\.[0-9]+[.0-9A-Za-z]*$/ (mecab-version)))) 
     148 
     149(test-section "mecab-strerror") 
     150(mecab-new2 "") 
     151(test* "at mecab-new2 (ok)" "" (mecab-strerror #f)) 
     152 
     153(mecab-new2 "-d //") ;; => "tagger.cpp(149) [load_dictionary_resource(param)] param.cpp(71) [ifs] no such file or directory:  //dicrc" 
     154(test* "at mecab-new (err)" #f (string=? "" (mecab-strerror #f))) 
     155(test* "no such file or directory" #f (not (#/no such file or directory/ (mecab-strerror #f)))) 
     156 
     157(let1 m (mecab-new2 "") 
     158  (mecab-sparse-tostr m "��Ĥ���") 
     159  (test* "noerr" "" (mecab-strerror m)) 
     160  (mecab-destroy m)) 
     161 
     162(let1 m (mecab-new2 "") 
     163  (test-section "mecab-get-partial / mecab-set-partial") 
     164  (test* "default partial mode [0|1]" #t 
     165         (and (memq (mecab-get-partial m) '(0 1)) #t)) 
     166  (mecab-set-partial m 1) 
     167  (test* "set to 1" 1 (mecab-get-partial m)) 
     168  (mecab-set-partial m 0) 
     169  (test* "set to 0" 0 (mecab-get-partial m)) 
     170 
     171  (test-section "mecab-get-theta / mecab-set-theta") 
     172  (let1 theta (mecab-get-theta m) 
     173    (test* "default partial mode [0..1]" #t (and (number? theta) (<= 0.0 theta 1.0)))) 
     174  (mecab-set-theta m 1.0) 
     175  (test* "set to 1.0" 1.0 (mecab-get-theta m)) 
     176  (mecab-set-theta m 0.5) 
     177  (test* "set to 0.5" 0.5 (mecab-get-theta m)) 
     178 
     179  (test-section "mecab-get-lattice-level / mecab-set-lattice-level") 
     180  (test* "default lattice-level [0|1|2]" #t 
     181         (and (memq (mecab-get-lattice-level m) '(0 1 2)) #t)) 
     182  (mecab-set-lattice-level m 1) 
     183  (test* "set to 1" 1 (mecab-get-lattice-level m)) 
     184  (mecab-set-lattice-level m 2) 
     185  (test* "set to 2" 2 (mecab-get-lattice-level m)) 
     186  (mecab-set-lattice-level m 0) 
     187  (test* "set to 0" 0 (mecab-get-lattice-level m)) 
     188 
     189  (test-section "mecab-get-all-morphs / mecab-set-all-morphs") 
     190  (test* "default all-morphs [0|1]" #t 
     191         (and (memq (mecab-get-all-morphs m) '(0 1)) #t)) 
     192  (mecab-set-all-morphs m 1) 
     193  (test* "set to 1" 1 (mecab-get-all-morphs m)) 
     194  (mecab-set-all-morphs m 0) 
     195  (test* "set to 0" 0 (mecab-get-all-morphs m)) 
     196  ) 
    40197 
    41198(test-end)Â