root/lang/scheme/gauche/bindings/cabocha/trunk/wrap-test.scm @ 128

Revision 124, 1.6 kB (checked in by naoya_t, 15 years ago)

added wrap.scm and more tests

Line 
1(require "./wrap")
2
3;(use gauche.test)
4;(test-start "cabocha")
5;(test-module 'cabocha)
6
7(define c (cabocha-new))
8;(test* "cabocha?" #t (cabocha? c))
9
10(define (pp-chunk chunk)
11  (let1 tokens-in-chunk (fourth chunk)
12;       (format #t "~d) => ~d ~a // head=~a func=~a score:~a\n"
13;       (format #t "~a // head=~a func=~a score:~a\n"
14        (format #t "~a // head=~a func=~a\n"
15;                       (second chunk)
16;                       (third chunk)
17                        (map token-surface (vector->list tokens-in-chunk))
18                        (token-surface (vector-ref tokens-in-chunk (fifth chunk)))
19                        (token-surface (vector-ref tokens-in-chunk (sixth chunk)))
20;                       (seventh chunk)
21                        )))
22
23(define (cparse sentence)
24  (let* ([s (string-append sentence "。")]
25                 [tree (cabocha-sparse-totree c s)]
26                 )
27        (format #t "\n「~a」\n" s)
28        (let* ([token-size (cabocha-tree-token-size tree)]
29                   [chunk-size (cabocha-tree-chunk-size tree)]
30                   [chunk-list (cabocha-tree-chunk-list tree)])
31          (format #t "token size: ~d, " token-size)
32          (format #t "chunk size: ~d\n" chunk-size)
33;         (for-each pp-chunk chunk-list)
34;         (print "-")
35          (let1 terminal-chunk (find (lambda (c) (= -1 (third c))) chunk-list)
36                ;(pp-chunk terminal-chunk)
37                (let loop ((level 0) (chunk terminal-chunk))
38                  (dotimes (i level) (display ": ")) (display "+- ")
39                  (pp-chunk chunk)
40                  (let1 link-from (filter (lambda (c) (= (second chunk) (third c))) chunk-list)
41                        ;(map pp-chunk link-from)
42                        (map (cut loop (+ level 1) <>) link-from))
43;                 (dotimes (i level) (display ": ")) (newline)
44                  ))
45          )))
46
47;(load "sentences.scm")
48;(for-each cparse sentences)
49(load "sentences.scm")
50(for-each cparse sentences)
51
52(cabocha-destroy c)
53;(test-end)
Note: See TracBrowser for help on using the browser.