Linux系统安装SCWS-1.2.3及PHP扩展

admin7年前技术文档2136

取得 scws-1.2.3 的代码

wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz21

解开压缩包

[hightman@d1 ~]$ tar xvjf scws-1.2.3.tar.bz21

进入目录执行配置脚本和编译

[hightman@d1 ~]$ cd scws-1.2.3
[hightman@d1 ~/scws-1.2.3]$ ./configure --prefix=/usr/local/scws
[hightman@d1 ~/scws-1.2.3]$ make
[hightman@d1 ~/scws-1.2.3]$ make install

注:这里和通用的 GNU 软件安装方式一样,具体选项参数执行 ./configure –help 查看。 
常用选项为:–prefix=

[hightman@d1 ~/scws-1.2.3]$ ls -al /usr/local/scws/lib/libscws.la1

试试执行 scws-cli 文件

[hightman@d1 ~/scws-1.2.3]$ /usr/local/scws/bin/scws -h
scws (scws-cli/1.2.3)
Simple Chinese Word Segmentation - Command line usage.
Copyright (C)2007 by hightman....

用 wget 下载并解压词典,或从主页下载然后自行解压再将 *.xdb 放入 /usr/local/scws/etc 目录中

[hightman@d1 ~/scws-1.2.3]$ cd /usr/local/scws/etc
[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-cht-utf8.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-gbk.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-utf8.tar.bz2
[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-cht-utf8.tar.bz2

安装 php 扩展

假设您已经将 scws 按上述步骤安装到 /usr/local/scws 中。 
安装此扩展要求您的 php 和系统环境安装了相应的 autoconf automake 工具及 phpize 。

  1. 进入源码目录的 phpext/ 目录 ( cd ~/scws-1.2.3 )

  2. 执行 phpize (在PHP安装目录的bin/目录下)

  3. 执行 ./configure --with-scws=/usr/local/scws 若 php 安装在特殊目录 $php_prefix, 则请在 configure 后加上 --with-php-config=$php_prefix/bin/php-config

  4. 执行 make 然后用 root 身份执行 make install

  5. 在 php.ini 中加入以下几行 
    [scws] 

    ; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空, 
    ; 再把 extension = scws.so 指定绝对路径。 

    extension = scws.so 
    scws.default.charset = utf8 
    scws.default.fpath = /usr/local/scws/etc 

  6. 重启php使新的 php.ini 生效。命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分。

  7. 如果重启php-fpm过程中出现错误信息 
    NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/opt/rh/php55/root/usr/lib64/php/modules/scws.so' - libscws.so.1: cannot open shared object file: No such file or directory in Unknown on line 0 
    则需要建两个软连接: 
    ln -s /usr/local/scws/lib/libscws.so.1.1.0 /usr/local/lib/libscws.so 
    ln -s /usr/local/scws/lib/libscws.so.1.1.0 /usr/local/lib/libscws.so.1

  8. 这样就算安装完成了,余下的工作只是PHP代码编写问题了。


使用php扩展:使用方法详见:https://github.com/hightman/scws/blob/master/phpext/README.md

$sh = scws_open();
scws_set_charset($sh, 'utf8');
scws_set_dict($sh, '/usr/local/scws/etc/dict.utf8.xdb');
scws_set_rule($sh, '/usr/local/scws/etc/rules.ini');
$text = "我是一个中国人,我会C++语言,我也有很多T恤衣服";
scws_send_text($sh, $text);
$top = scws_get_tops($sh, 5);
print_r($top);
Array
(
    [0] => Array
        (
            [word] => C++
            [times] => 1
            [weight] => 9.5
            [attr] => nz
        )

    [1] => Array
        (
            [word] => T恤
            [times] => 1
            [weight] => 5.5
            [attr] => n
        )

    [2] => Array
        (
            [word] => 我会
            [times] => 1
            [weight] => 4.9400000572205
            [attr] => r
        )

    [3] => Array
        (
            [word] => 很多
            [times] => 1
            [weight] => 4.9200000762939
            [attr] => m
        )

    [4] => Array
        (
            [word] => 衣服
            [times] => 1
            [weight] => 4.9200000762939
            [attr] => n
        )

)


分享到:

相关文章

Win8重装及恢复系统方法

Win8重装及恢复系统方法

Win8重装及恢复系统方法  win8正式版已经发布了一段时间,大家纷纷进行试用,如果操作系统出现问题了怎么办,我们该怎么进行恢复呢?本文就教大家如何重装及恢复win8系统。   &nb...

Nginx反向代理Google扩展ngx_http_google_filter_module

Nginx反向代理Google扩展ngx_http_google_filter_module

模块介绍ngx_http_google_filter_module 是一个过滤器模块,能够让谷歌镜像更便捷的部署。内建了正则表达式、URI locations和其他复杂的配置。原生nginx模块确保了...

推荐一些国内的Jquery CDN免费服务

Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影。很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快。之前火端网络的一些网站都是使用Google的...

最常用的架构模式

最常用的架构模式

观其设计知其人A MAN is KNOWN by the DESIGN he keeps原文:Most Useful Software Architecture Patterns by Sh...

什么是“堆”,"栈","堆栈","队列",它们的区别

什么是“堆”,"栈","堆栈","队列",它们的区别

如果你学过数据结构,就一定会遇到“堆”,"栈","堆栈","队列",而最关键的是这些到底是什么意思?最关键的是即使你去面试,这些都还会问到,...


这里我选择centos7-x86 64 右键 复制链接。

在centos系统中执行

centos7 安装最新版postgresql10

    一、更新源地址:https://yum.postgresql.org/repopackages.php这里我选择centos7-x86 64 右键 复制...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。