美文网首页
scws自定义词库

scws自定义词库

作者: xiasix | 来源:发表于2016-01-15 09:46 被阅读0次

有个违禁词库的需求,也可以做关键词提取,我们的搜索的词库用的是httpcws 张宴先生的,他的词库封装进去了 不能编译,scws支持自定义词库 很好用。

cd /Data/tgz/

wgethttp://www.xunsearch.com/scws/down/scws-1.2.2.tar.bz2

tar xvjf scws-1.2.2.tar.bz2

cd scws-1.2.2

./configure --prefix=/Data/apps/scws

make

make install

cd phpext/

ls

/Data/apps/php/bin/phpize

./configure --with-scws=/Data/apps/scws/ --with-php-config=/Data/apps/php/bin/php-config

make

make install

vi /Data/apps/php/etc/php.ini

添加

extension =scws.so

scws.default.charset = utf8

scws.default.fpath = /Data/apps/scws/etc

保存退出

killall php-fpm

/Data/apps/php/sbin/php-fpm

词库起名为lianchuang.txt

放到/Data/apps/scws/etc下

格式

麻痹性斜视    1.0    1.0    @

麻痹性痴呆    1.0    1.0    @

麻痹性肠梗阻    1.0    1.0    @

麻痹性臂丛神经炎    1.0    1.0    @

麻醉    1.0    1.0    @

麻风    1.0    1.0    @

用法

$content=$this->getRequest()->getQuery('content','');

$scws= scws_new();

$scws->set_charset('utf8');

// 这里没有调用 set_dict 和 set_rule 系统会自动试调用 ini 中指定路径下的词典和规则文件

$scws->send_text($content);

$scws->add_dict(ini_get("scws.default.fpath")."/lianchuang.txt",SCWS_XDICT_TXT);

$scws->set_ignore(false);

//是否复式分割,如“中国人”返回“中国+人+中国人”三个词。

$scws->set_multi(false);

//设定将文字自动以二字分词法聚合

$scws->set_duality(true);

$result=$scws->get_words('@');

if(is_array($result) &&count($result) >0) {

$words= [];

foreach($resultas$key=>$value) {

$words[] =$value['word'];

}

var_dump($words);

}

$scws->close();

相关文章

网友评论

      本文标题:scws自定义词库

      本文链接:https://www.haomeiwen.com/subject/asdhkttx.html