CaboChaのCインターフェイス - アールメカブ

アールメカブ


CaboChaのCインターフェイス

Programming

cc -O2 `cabocha-config --cflags` cabochaTest.c -o cabochaTest `cabocha-config --libs`

$ ./cabochaTest -f2 -O2

#include <cabocha.h>
#include <stdio.h>

int main (int argc, char **argv) 
{
  cabocha_t *c;
  char p[1024] = "太郎は次郎が持っている本を花子に渡した。";

  c = cabocha_new(argc, argv);

  printf ("argc = %d, INPUT: %s arg: %s\n", argc, p, *(argv+1));
  printf ("RESULT:\n%s", cabocha_sparse_tostr(c, p));

  cabocha_destroy(c);
   
  return 0;
}

mapなどのSTLを使うつもりで,CPP ファイルにすると,キャストでうるさく文句を言われる.

...
char p[] = "太郎は花子が持っている本を次郎に渡した。";
cabocha_t *cabocha = cabocha_new(argc, argv);
cabocha_tree_t *tree = 0;
...
tree = cabocha_sparse_totree(cabocha, p) ;
$ g++ -O2 `cabocha-config --cflags` cabocha3.cpp
                -o cabocha3 `cabocha-config --libs`
cabocha3.cpp:38: error: invalid conversion from
  ‘const cabocha_tree_t*’ to ‘cabocha_tree_t*’

しようがないのでキャストする

tree = const_cast<cabocha_tree_t*> 
        (cabocha_sparse_totree(cabocha, p) );
 
Link: Programming(4983d) CaBoCha(4989d) 日録2008年_2月(5538d)
Last-modified: 2008-08-28 (木) 09:43:38 (5718d)