;;; ;;; cabochalib.stub ;;; ;;; 2009.3.15 by naoya_t ;;; " #include #include #include #include \"mecab.h\" #include #include \"cabocha.h\" " ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-cclass "ScmCaboCha*" "Scm_CaboChaClass" () ()) (define-type "cabocha_t*" "cabocha_t" "SCM_CABOCHAP" "unwrap_cabocha_t" "wrap_cabocha_t") (define-cclass "ScmCaboChaTree*" "Scm_CaboChaTreeClass" () ()) (define-type "cabocha_tree_t*" "cabocha_tree_t" "SCM_CABOCHA_TREEP" "unwrap_cabocha_tree_t" "wrap_cabocha_tree_t") (define-cclass "ScmCaboChaChunk*" "Scm_CaboChaChunkClass" () ()) (define-type "cabocha_chunk_t*" "cabocha_chunk_t" "SCM_CABOCHA_CHUNKP" "unwrap_cabocha_chunk_t" "wrap_cabocha_chunk_t") (define-cclass "ScmCaboChaToken*" "Scm_CaboChaTokenClass" () ()) (define-type "cabocha_token_t*" "cabocha_token_t" "SCM_CABOCHA_TOKENP" "unwrap_cabocha_token_t" "wrap_cabocha_token_t") ;;; ;(define-cclass "ScmMeCab*" "Scm_MeCabClass" () ()) (define-cclass "ScmMeCabNode*" "Scm_MeCabNodeClass" () ()) ;(define-cclass "ScmMeCabDictionaryInfo*" "Scm_MeCabDictionaryInfoClass" () ()) (define-type "const mecab_node_t*" "const mecab_node_t" "SCM_MECAB_NODEP" "unwrap_mecab_node_t" "wrap_mecab_node_t") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-cproc cabocha-do (&rest args) (expr "cabocha_call_int_func(&cabocha_do,args)")) ;; ;; parser ;; ;;cabocha_t *cabocha_new(int argc, char **argv) ;; cabocha のインスタンスを生成します. ;; 引数には, C 言語の, main 関数で使用される argc, argv スタイルの引数を与えます. ;; この引数は, cabocha コマンドと同じ方法で処理されます. ;; 成功すれば, cabocha_t 型のポインタが返ってきます. このポインタを通して解析を行います. (define-cproc cabocha-new (&rest args) (expr "cabocha_call_cabocha_func(&cabocha_new,args)")) ;;cabocha_t *cabocha_new2(char *arg) ;; cabocha のインスタンスを生成します. ;; 引数には, 一つの文字列として表現したパラメータを与えます. ;; この引数は, cabocha コマンドと同じ方法で処理されますが, ;; 文字列を解釈するルーチンが貧弱なので留意してください. ;; 成功すれば, cabocha_t 型のポインタが返ってきます. このポインタを通して解析を行います. (define-cproc cabocha-new2 (arg::) (call "cabocha_new2")) ;;char *cabocha_sparse_tostr(cabocha_t *p, char *str) ;; 解析を行います. 引数には, cabocha_new で得られた cabocha_t 型のポインタと, ;; 各レイヤの1解析単位を1つの文字列で表現した char 型のポインタ文字列を与えます. ;; デフォルトの動作ならば, 引数の文字列は生文となります. ;; 成功すれば, 解析後の結果が char 型のポインタとして返ってきます. ;; 戻り値のポインタが指すメモリ領域は, 呼び出し側で管理する必要はありませんが, ;; cabocha_sparse_tostr を呼ぶ度に上書きされます. ;; また, cabocha_destroy を呼ぶと解放されます. (define-cproc cabocha-sparse-tostr (c:: str::) (call "cabocha_sparse_tostr")) ;;char *cabocha_sparse_tostr2 (cabocha_t *m, char *str, unsigned int len) ;; cabocha_sparse_tostr とほぼ同じですが, len にて, 解析する文の長さを指定できます. (define-cproc cabocha-sparse-tostr2 (c:: str:: len::) (call "cabocha_sparse_tostr2")) ;;char *cabocha_sparse_tostr3 (cabocha_t *m, char *istr,unsigned int ilen char *ostr,unsigned int olen) ;; cabocha_sparse_tostr2 に加え, 出力用のバッファ領域 (ostr), 及びその長さ (olen) を指定できます. ostr の領域の管理は, 呼び出し側が行います. 成功すれば, 解析後の結果が char 型のポインタとして返ってきます. これは, ostr と同じになります. もし, 解析結果の長さが olen 以上になった場合は, 解析失敗とみなし, NULL を返します. ;;char *cabocha_strerror (cabocha_t* m) ;; エラーの内容を文字列として取得します. cabocha_sparse_tostr 等で, NULL が返ってきた場合に, cabocha_strerror を呼ぶことで, エラーの内容を取得できます. cabocha_new,cabocha_new2 のエラーは, m を NULL と指定してください. (define-cproc cabocha-strerror (c::) (call "cabocha_strerror")) ;;void cabocha_destroy(cabocha_t *p) ;; cabocha_t 型のポインタを解放します. ;;(define-cproc cabocha-destroy (c::) ;; (call "cabocha_destroy")) (define-cproc cabocha-destroy (p::) " if (p->c) { cabocha_destroy(p->c); p->c = NULL; } SCM_RETURN(SCM_UNDEFINED); ") (define-cproc cabocha-destroyed? (c::) " SCM_RETURN(SCM_MAKE_BOOL(c == NULL)); ") ;; (define-cproc cabocha-sparse-totree (c:: str::) (call "cabocha_sparse_totree")) (define-cproc cabocha-sparse-totree2 (c:: str:: len::) (call "cabocha_sparse_totree2")) ;; ;; tree ;; (define-cproc cabocha-tree-new () (call "cabocha_tree_new")) (define-cproc cabocha-tree-destroy (tree::) (call "cabocha_tree_destroy")) (define-cproc cabocha-tree-empty (tree::) (call "cabocha_tree_empty")) (define-cproc cabocha-tree-clear (tree::) (call "cabocha_tree_clear")) (define-cproc cabocha-tree-clear-chunk (tree::) (call "cabocha_tree_clear_chunk")) (define-cproc cabocha-tree-size (tree::) (call "cabocha_tree_size")) (define-cproc cabocha-tree-chunk-size (tree::) (call "cabocha_tree_chunk_size")) (define-cproc cabocha-tree-token-size (tree::) (call "cabocha_tree_token_size")) (define-cproc cabocha-tree-sentence (tree::) (call "cabocha_tree_sentence")) (define-cproc cabocha-tree-sentence-size (tree::) (call "cabocha_tree_sentence_size")) (define-cproc cabocha-tree-set-sentence (tree:: sentence:: length::) (call "cabocha_tree_set_sentence")) (define-cproc cabocha-tree-read (tree:: input:: length:: input-layer::) ;; cabocha_input_layer_t : enum { INPUT_RAW_SENTENCE, _POS, _CHUNK, _SELECTION, _DEP } (call "cabocha_tree_read")) (define-cproc cabocha-tree-read-from-mecab-node (tree:: node::) (call "cabocha_tree_read_from_mecab_node")) (define-cproc cabocha-tree-token (tree:: i::) (call "cabocha_tree_token")) ;; const (define-cproc cabocha-tree-chunk (tree:: i::) (call "cabocha_tree_chunk")) ;; const (define-cproc cabocha-tree-add-token (tree::) (call "cabocha_tree_add_token")) (define-cproc cabocha-tree-add-chunk (tree::) (call "cabocha_tree_add_chunk")) (define-cproc cabocha-tree-strdup (tree:: str::) (call "cabocha_tree_strdup")) (define-cproc cabocha-tree-alloc (tree:: size::) (call "cabocha_tree_alloc")) (define-cproc cabocha-tree-tostr (tree:: format::) ;; cabocha_format_t : ENUM { FORMAT-TREE -LATTICE -TREE_LATTICE -XML -NONE } (call "cabocha_tree_tostr")) ;(define-cproc cabocha-tree-tostr2 (tree:: format:: length::) ; const char *cabocha_tree_tostr2(cabocha_tree_t* tree, cabocha_format_t format, ; char *str, size_t length); (define-cproc cabocha-tree-set-charset (tree:: charset::) ;; cabocha_charset_t : enum { EUC_JP, CP932, UTF8, ASCII } (call "cabocha_tree_set_charset")) (define-cproc cabocha-tree-charset (tree::) (call "cabocha_tree_charset")) ;; cabocha_charset_t (define-cproc cabocha-tree-set-posset (tree:: posset::) ;; cabocha_posset_t : enum { IPA, JUMAN } (call "cabocha_tree_set_posset")) (define-cproc cabocha-tree-posset (tree::) (call "cabocha_tree_posset")) ;; cabocha_posset_t (define-cproc cabocha-tree-set-output-layer (tree:: output-layer::) ;; cabocha_output_layer_t : enum { OUTPUT*_RAW_SENTENCE, _POS, _CHUNK, _SELECTION, _DEP } (call "cabocha_tree_set_output_layer")) (define-cproc cabocha-tree-output-layer (tree::) (call "cabocha_tree_output_layer")) ;; cabocha_output_layer_t (define-cproc cabocha-learn (&rest args) (expr "cabocha_call_int_func(&cabocha_learn,args)")) (define-cproc cabocha-system-eval (&rest args) (expr "cabocha_call_int_func(&cabocha_system_eval,args)")) (define-cproc cabocha-model-index (&rest args) (expr "cabocha_call_int_func(&cabocha_model_index,args)")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-cproc cabocha-chunk-link (chunk::) (expr "chunk->link")) (define-cproc cabocha-chunk-head-pos (chunk::) (expr "chunk->head_pos")) (define-cproc cabocha-chunk-func-pos (chunk::) (expr "chunk->func_pos")) (define-cproc cabocha-chunk-token-size (chunk::) (expr "chunk->token_size")) (define-cproc cabocha-chunk-token-pos (chunk::) (expr "chunk->token_pos")) (define-cproc cabocha-chunk-score (chunk::) (expr "chunk->score")) (define-cproc cabocha-chunk-feature-list (chunk::) " return Scm_MakeStringList(chunk->feature_list,chunk->feature_list_size);") (define-cproc cabocha-chunk-feature-list-size (chunk::) (expr "chunk->feature_list_size")) (define-cproc cabocha-token-surface (token::) (expr "token->surface")) (define-cproc cabocha-token-normalized-surface (token::) (expr "token->normalized_surface")) (define-cproc cabocha-token-feature (token::) (expr "token->feature")) (define-cproc cabocha-token-feature-list (token::) " return Scm_MakeStringList(token->feature_list,token->feature_list_size);") (define-cproc cabocha-token-feature-list-size (token::) (expr "token->feature_list_size")) (define-cproc cabocha-token-ne (token::) (expr "token->ne")) (define-cproc cabocha-token-chunk (token::) (expr "token->chunk")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Local variables: ;; mode: scheme ;; end: