chise_swig_perl

これは何?

CHISEライブラリ(concord + libchise)をPerlで利用するための仕組みです。SWIGを利用しています。Windows(Cygwin)でも利用できます。

ダウンロード

CHISE projectのレポジトリよりソースコードを入手可能です。

内容

ビルド

すでにconcordとlibchiseが使える状態であると仮定します。以下のようにビルドを行ってください。

GNU/Linux

% swig -c++ -perl -I/usr/local/include chise.i
% g++ -c chise_wrap.cxx -I/usr/lib/perl/5.8/CORE
% g++ -shared -lchise chise_wrap.o -o chise.so -Wl,-rpath,/usr/local/lib

Cygwin

$ swig -c++ -perl -I/usr/local/include chise.i
$ g++ -c chise_wrap.cxx -I/usr/lib/perl5/5.8/cygwin/CORE
$ g++ -shared chise_wrap.o -L/usr/local/lib -L/usr/lib/perl5/5.8/cygwin/CORE -o chise.dll -Wl,-rpath,/usr/local/lib -lchise -lconcord -lperl

(上記はCGI等で利用するために -Wl,-rpath,/usr/local/lib のオプションを含めてライブラリパスも埋め込んでいます)

完了

最終的に以下のファイルを利用します

サンプル

CHISEデータベースで「mother」を持つ素性の関係図(要ImageMagick)

$TEMPFILE = "temp.txt";
$IMAGEMAGICK = "/usr/local/bin/dot";
$OUTPUTTYPE = "png";
$OUTPUTFILE = "tree.png";

use chise;
$chise = new chise;

@feature = $chise->get_feature_list();
$result = "";
foreach(@feature){
  $temp = $chise->feature_gets_property_value($_, "mother");
  if($temp ne ""){
    $result .= "\t\"$_\" -> \"$temp\";\n";
  #} else {
  #  $result .= "\t\"$_\";\n";
  }
}

open FH, ">$TEMPFILE";
print FH "digraph {\n\trankdir = \"RL\";\n$result}";
close FH;

$dummy = `$IMAGEMAGICK -T$OUTPUTTYPE -o$OUTPUTFILE $TEMPFILE`;

実行結果

tree.png

このほか、CHISE漢字連環図も参考とすることができます。

Cygwin Tips

残念ながらCygwinではCHISEデータベースを構築できませんので、他からファイルをインポートする必要があります。デフォルトでは /usr/local/share/chise/1.0/db 以下にBerkeley DBのファイル群がありますので、まるごとコピーします。

Cygwinでの concord および libchise のビルドができるようになりました。ただし「CFLAGS=-DHAVE_STRNLEN」が必要です。

concord

(get concord source from cvs)
$ ./configure CFLAGS=-DHAVE_STRNLEN
$ make
$ make install

libchise

(get libchise source from cvs)
$ export LD_LIBRARY_PATH=/usr/local/lib
$ ./configure CFLAGS=-DHAVE_STRNLEN
$ make
$ make install

ToDo

現状

**ok** CHISE_DS* CHISE_DS_open (CHISE_DS_Type type, const unsigned char* location, int subtype, int modemask);
**ok** int CHISE_DS_close (CHISE_DS* ds);
**ok** int chise_ds_foreach_char_feature_name (CHISE_DS* ds, int (*func) (CHISE_DS* ds, unsigned char* name));

*done* CHISE_CCS chise_ds_get_ccs (CHISE_DS* ds, const unsigned char* name);
*done* static inline CHISE_Char_ID chise_ds_decode_char (CHISE_DS* ds, const unsigned char* ccs, int code_point);
*done* CHISE_Feature chise_ds_get_feature (CHISE_DS* ds, const unsigned char* name);
*done* CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
*done* CHISE_Property chise_ds_get_property (CHISE_DS* ds, const unsigned char* name);
*done* unsigned char* chise_feature_gets_property_value (CHISE_Feature feature, CHISE_Property property, unsigned char* buf, size_t size);
*done* unsigned char* chise_char_gets_feature_value (CHISE_Char_ID cid, CHISE_Feature feature, unsigned char* dst, size_t size);
*done* extern const unsigned char chise_db_format_version[];
*done* extern const unsigned char chise_db_dir[];
*done* extern const unsigned char chise_system_db_dir[];
*done* unsigned char* chise_ds_location (CHISE_DS* ds);

*skip* int chise_value_size (const CHISE_Value* s);
*skip* unsigned char* chise_value_data (const CHISE_Value* s);
*skip* unsigned char* chise_value_to_c_string (const CHISE_Value* s);
*skip* int chise_char_load_feature_value (CHISE_Char_ID cid, CHISE_Feature feature, CHISE_Value* valdatum);
*skip* static inline int chise_ds_load_char_feature_value (CHISE_DS* ds, CHISE_Char_ID cid, const unsigned char* name, CHISE_Value* valdatum);
*skip* int chise_feature_load_property_value (CHISE_Feature feature, CHISE_Property property, CHISE_Value* valdatum);
*skip* int chise_feature_foreach_char_with_value (CHISE_Feature feature, int (*func) (CHISE_Char_ID cid, CHISE_Feature feature, CHISE_Value* valdatum));

int chise_char_set_feature_value (CHISE_Char_ID cid, CHISE_Feature feature, unsigned char* value);
int chise_feature_set_property_value (CHISE_Feature feature, CHISE_Property property, unsigned char* value);
int chise_ccs_set_decoded_char (CHISE_CCS ccs, int code_point, CHISE_Char_ID cid);

int chise_feature_setup_db (CHISE_Feature feature, int writable);
int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
int chise_property_setup_db (CHISE_Property property, int writable);

int chise_feature_sync (CHISE_Feature feature);
int chise_ccs_sync (CHISE_CCS ccs);
int chise_property_sync (CHISE_Property property);

Last-modified: 2020-11-01 (日) 16:50:30