前言:
第一篇文章講完了Linux環(huán)境下安裝scws分詞工具php插件的前期工作辆床,接下來(lái)我們將開(kāi)始正式用phpize編譯安裝Php的SCWS插件了9艉纭饶火!
用phpize編譯安裝Php的SCWS插件
如果上述環(huán)境都沒(méi)有任何問(wèn)題米愿,那么接下來(lái)你可以正式開(kāi)始你的SCWS分詞工具安裝了:
-
- 進(jìn)入scws-1.2.3安裝源碼的目錄 phpext/
cd ~/scws-1.2.3/phpext/
-
- 在/phpext/目錄中執(zhí)行PHP安裝目錄下的bin目錄下的phpize
安裝命令如下(Php5.5):
# /opt/remi/php55/root/bin/phpize
Php7.0的安裝方式就用如下命令:
# /opt/remi/php70/root/bin/phpize
返回如下:
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212 - 在/phpext/目錄中執(zhí)行PHP安裝目錄下的bin目錄下的phpize
如果你是Php7.0的話用就用如下命令:
# /opt/remi/php70/root/bin/phpize
返回如下:
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
- 就在上面的當(dāng)前目錄執(zhí)行
# ./configure --with-scws=/usr/local/scws
結(jié)果有提示如下錯(cuò)誤:
configure: error: Cannot find php-config. Please use --with-php-config=PAT
看來(lái)我們需要指定文件php-config的具體位置了减噪,改成如下的形式:
命令如下(Php5.5):
# ./configure --with-scws=/usr/local/scws--with-php-config=/opt/remi/php55/root/bin/php-config
如果你是Php7.0的話用就用如下命令:
# ./configure --with-scws=/usr/local/scws --with-php-config=/opt/remi/php70/root/bin/php-config
返回了一堆的信息短绸,那么恭喜你车吹,估計(jì)你應(yīng)該離成功不遠(yuǎn)了。
-
執(zhí)行
make
返回如下信息:Libraries have been installed in:
/root/scsws-1.2.3/phpext/modulesIf you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the
LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to theLD_RUN_PATH' environment variable during linking - use the
-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
Build complete.
Don't forget to run 'make test'. 然后用 root 身份執(zhí)行
make install
返回如下信息的話證明SCWS分詞插件安裝成功醋闭!
PHP5.5環(huán)境返回信息
Installing shared extensions: /opt/remi/php55/root/usr/lib64/php/modules/
PHP7.0環(huán)境返回信息
Installing shared extensions: /opt/remi/php70/root/usr/lib64/php/modules/
- 最后一步是在 php.ini 文件中加入以下幾行
PHP5.5的路徑
/opt/remi/php55/root/etc/php.ini
PHP7.0的路徑跟Php5.5的路徑略有不同
/etc/opt/remi/php70/php.ini
[scws]
;
; 注意請(qǐng)檢查 php.ini 中的 extension_dir 的設(shè)定值是否正確, 否則請(qǐng)將 extension_dir 設(shè)為空窄驹,
; 再把 extension = scws.so 指定絕對(duì)路徑。
;
extension = scws.so
scws.default.charset = gbk
scws.default.fpath = /usr/local/scws/etc
注:上文的
scws.default.charset = gbk
可按你的需要改為scws.default.charset = UTF-8
設(shè)定完畢保存证逻,再重啟php服務(wù)
# systemctl restart php55-php-fpm.service
才能使新的 php.ini 生效乐埠,查看phpinfo信息如下圖:
測(cè)試分詞效果:
Linux系的服務(wù)器測(cè)試代碼test.php如下
<?php
$msg = '大家好,我的名字叫李白囚企,很高興認(rèn)識(shí)大家丈咐!';
$shfc = scws_open();
scws_set_dict($shfc, '/usr/local/scws/etc/dict.utf8.xdb');
scws_set_rule($shfc, '/usr/local/scws/etc/rules.utf8.ini');
scws_set_ignore($shfc,true);
scws_send_text($shfc, $msg);
$Amsg2 = scws_get_result($shfc);
scws_close($shfc);
foreach($Amsg2 as $value)
{
foreach($value as $key => $value2)
{
echo $value2 .',';
}
echo '<br />';
}
?>
如果是windows系的服務(wù)器的話,只需要把上面的詞庫(kù)地址的參數(shù)更改為相應(yīng)的地址就行龙宏。
scws_set_dict($shfc, ini_get("scws.default.fpath").'\dict.utf8.xdb', SCWS_XDICT_XDB);
或者是
scws_set_dict($shfc,'c:\program Files\scws\dict.utf8.xdb', SCWS_XDICT_XDB);
運(yùn)行結(jié)果見(jiàn)下圖棵逊。
至此SCWS已成功安裝完畢,接下來(lái)的使用就不在本文的討論范圍了银酗,下面主要說(shuō)一下SCWS-1.2.3的自定義詞庫(kù)辆影,另外開(kāi)篇吧!
Tag:Php分詞, SCWS, 分詞技術(shù)
發(fā)布時(shí)間:2015年10月22日
博客被黑花吟,挪窩簡(jiǎn)書安家……