$Id: libcabocha.html,v 1.1 2003/01/30 17:26:14 taku-ku Exp $;
CaboChaには, C/C++ 共用のライブラリ
(cabocha.h, libcabocha.so/licabocha.dll) があります.
C ライブラリは以下の関数を提供しています.
cabocha_t *cabocha_new(int argc, char **argv)cabocha_t *cabocha_new2(char *arg)char *cabocha_sparse_tostr(cabocha_t *p, char
*str)char *cabocha_sparse_tostr2 (cabocha_t *m, char *str,
unsigned int len)char *cabocha_sparse_tostr3 (cabocha_t *m, char
*istr,unsigned int ilen char *ostr,unsigned int olen)char *cabocha_strerror (cabocha_t* m)void cabocha_destroy(cabocha_t *p)example.c
#include <cabocha.h>
#include <stdio.h>
int main (int argc, char **argv)
{
cabocha_t *c;
char p[1024] = "太郎は次郎が持っている本を花子に渡した。";
c = cabocha_new(argc, argv);
printf ("INPUT: %s\n", p);
printf ("RESULT:\n%s", cabocha_sparse_tostr(c, p));
cabocha_destroy(c);
return 0;
}
準備中. src/cabocha.h, example/example2.cpp を参考にしてください.
% cc -O2 `cabocha-config --cflags` example.c -o example \
`cabocha-config --libs`
まず, コンパイル作業を行うディレクトリに cabocha.h, libcabocha.dll, をコピーします.
この後の作業は, 使用するコンパイラによって微妙に変わります.
cygwin/mingw 環境の場合
% gcc -DDLL_IMPORT -I. example.c -o example.exe libcabocha.dll
Visual Studio .NET C++の場合
% cl -DDLL_IMPORT -I. example.c libcabocha.lib
BCC32 環境の場合
インポートライブラリの作成 % implib.exe /a /f libcabocha.lib libcabocha.dll コンパイル % bcc32 -DDLL_IMPORT -I. example.c libcabocha.lib
さらに, 以下例ように, libcabocha.dll と動的 にリンクすることも可能です. 以下の方法は, どのようなコンパイラ (VCC, gcc, bcc)でも動作すると思います. この場合は, インポートライブラリを作成する必要はありません.
#include <stdio.h>
#include <windows.h>
typedef void* (WINAPI *FPINIT) (int, char **);
typedef char* (WINAPI *FPPARSE) (void*, char*);
typedef void (WINAPI *FPDEL) (void *);
int main (int argc, char **argv)
{
char p[] = "太郎は次郎が持っている本を花子に渡した。";
HINSTANCE hLib = LoadLibrary("libcabocha.dll");
if (hLib) {
FPINIT fpInit = (FPINIT) GetProcAddress (hLib, "cabocha_new");
FPPARSE fpParse = (FPPARSE) GetProcAddress (hLib, "cabocha_sparse_tostr");
FPDEL fpDel = (FPDEL) GetProcAddress (hLib, "cabocha_destroy");
if (fpInit && fpParse && fpDel) {
void *c = (*fpInit) (argc, argv);
printf ("INPUT: %s\n", p);
printf ("RESULT:\n%s", (*fpParse)(c, p));
(*fpDel)(c);
}
FreeLibrary(hLib);
}
return 0;
}
Perl, Ruby, Python といったスクリプト言語から, 直接
CaboChaを呼ぶことができます.
詳しくは, ruby/README, perl/README, python/README
をご覧ください.
$Id: libcabocha.html,v 1.1 2003/01/30 17:26:14 taku-ku Exp $;
taku-ku@is.aist-nara.ac.jp