root/lang/scheme/gauche/bindings/cabocha/trunk/wrap.scm @ 130

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

added wrap.scm and more tests

Line 
1;;;
2;;; cabocha wrapper
3;;;
4;;;  2009.3.22 by naoya_t
5;;;
6
7(use srfi-1)
8(use cabocha)
9
10;;; lib
11(define (vector-range vec from size)
12  (let1 vec* (make-vector size)
13        (dotimes (i size)
14          (vector-set! vec* i (vector-ref vec (+ from i))))
15        vec*))
16
17;;; cabocha token/chunk -> sexp
18(define (cabocha-token->sexp tok)
19  `(cabocha-token ,(cabocha-token-normalized-surface tok)
20                                  ,(cabocha-token-feature-list tok)
21                                  ))
22
23(define (token-surface token) (second token))
24(define (token-feature token) (third token))
25
26(define (cabocha-chunk->sexp i ch tokens)
27  (let* ([token-pos (cabocha-chunk-token-pos ch)]
28                 [token-size (cabocha-chunk-token-size ch)]
29                 [tokens-in-chunk (vector-range tokens token-pos token-size)]
30                 [token-head-pos (cabocha-chunk-head-pos ch)]
31                 [token-func-pos (cabocha-chunk-func-pos ch)])
32        `(cabocha-chunk ,i
33                                        ,(cabocha-chunk-link ch)
34                                        ,tokens-in-chunk
35                                        ,token-head-pos
36                                        ,token-func-pos
37                                        ,(cabocha-chunk-score ch)
38                                        )))
39
40#|
41(define (cabocha-tree-chunk-list t)
42  (let loop ([i (- (cabocha-tree-chunk-size t) 1)] [lis '()])
43        (if (< i 0) lis
44                (loop (- i 1)
45                          (cons (cabocha-chunk->sexp i (cabocha-tree-chunk t i)) lis) ))))
46
47(define (cabocha-tree-token-list t)
48  (let loop ([i (- (cabocha-tree-token-size t) 1)] [lis '()])
49        (if (< i 0) lis
50                (loop (- i 1)
51                          (cons (cabocha-token->sexp (cabocha-tree-token t i)) lis) ))))
52|#
53
54(define (cabocha-tree-chunks t) ;vec
55  (let* ([tokens (cabocha-tree-tokens t)]
56                 [chunk-size (cabocha-tree-chunk-size t)]
57                 [vec (make-vector chunk-size)])
58        (dotimes (i chunk-size)
59          (vector-set! vec i (cabocha-chunk->sexp i (cabocha-tree-chunk t i) tokens) ))
60        vec))
61(define (cabocha-tree-chunk-list t) ;list
62  (let ([tokens (cabocha-tree-tokens t)]
63                [chunk-size (cabocha-tree-chunk-size t)])
64        (map (lambda (i) (cabocha-chunk->sexp i (cabocha-tree-chunk t i) tokens))
65                 (iota chunk-size))))
66
67(define (cabocha-tree-tokens t)
68  (let* ([token-size (cabocha-tree-token-size t)]
69                 [vec (make-vector token-size)])
70        (dotimes (i token-size)
71          (vector-set! vec i (cabocha-token->sexp (cabocha-tree-token t i)) ))
72        vec))
73(define (cabocha-tree-token-list t)
74  (let1 token-size (cabocha-tree-token-size t)
75        (map (lambda (i) (cabocha-token->sexp (cabocha-tree-token t i)))
76                 (iota token-size))))
Note: See TracBrowser for help on using the browser.