按照下面的方式安装scws(scws可以作为独立工具使用,也可以作为动态库,在c/c++程序中调用,也可以作为php扩展在php语言中调用)
bzip2 -d scws_1.x.x.tar.bz2 tar xvf scws_1.x.x.tar ./configure --prefix=scws_home make make install
ps:上述操作完成后,scws已经安装成功,可以以命令行方式或在c/c++程序中使用scws
命令行方式使用swcs
cd scws_home ./scws -i ../etc/test.txt -o ../etc/out.txt -r ../etc/rules.utf8.ini -d ../etc/dict.utf8.xdb -c utf8
ps:字符串编码需要一致,scws使用时需要词典,词典文件,规则文件的编码要与被处理的文件内容编码一致。
如果想在c/c++中使用scws,需要做如下一些操作,很重要,特别是对php扩展的安装:
# 头文件考到这里 cp scws_home/include/scws /usr/include/scws # 作两个软连接(64位机器需要坐在/usr/lib64中) ln -s scws_home/lib/libscws.so.1.1.0 /usr/lib/libscws.so ln -s scws_home/lib/libscws.so.1.1.0 /usr/lib/libscws.so.1
安装php扩展
cd scws_1.x.x/phpext phpize ./configure --with-php-config=php_home/bin/php-config make make install
# 将上面生成的scws_home/phpext/modules/scws.so拷贝到你的php扩展目录,并且编辑php.ini,添加如下选项:
[scws]
extension = scws.so
scws.default.charset = utf8
scws.default.fpath = scws_home/etc
验证php扩展安装
cd scws_1.x.x/phpext
php scws_test.php
# 输出如下
test [1] ... pass!
test [2] ... pass!
test [3] ... pass!
test [4] ... pass!
test [5] ... pass!
test [6] ... pass!
test [7] ... pass!
test [8] ... pass!
test [9] ... pass!
test [10] ... pass!
test [11] ... pass!
test [12] ... pass!
test [13] ... pass!
test [14] ... pass!
test [15] ... pass!
// -------------------------------------
// test result report
// scws (module version:1.0.0, library version:1.2.0) - by hightman
// -------------------------------------
// total test: 15
// passed num: 15 (100.00%)
// failed num: 0 (0.00%)
// -------------------------------------
ok php扩展安装成功
