添加coreseek中文分词

官方说明地址: ​http://www.coreseek.cn/opensource/mmseg/

词典文件所在位置: 本地管理地址:xxx/dict/new_dict.txt【 每次添加新的词,先更新此文件, 然后再把最新的词典文件scp上传到sphinx所在服务器上更新词库】
线上词库配置地址: /export/coreseek/dict/


Step1: 生成词典文件 找出需要添加的词,存储到txt文档中,每个”词条“一行【请检查new_dict.txt中是否已经存在】

php 脚本输出格式化的词典文件 【换行加“ ”为了和原词典文件保持一致】

$file = '717add.txt';
$data = file($file);
$str = '';
foreach($data as $val) {
    $val = trim($val);
    $str .= $val. "	" . '1' . "
";
    $str .= 'x:1' . "
";    
}
file_put_contents('717add_dict.txt', $str);

Step2: 添加到原词典文件new_dict.txt中 

cat 717add_dict.txt >> new_dict.txt


Step3: 生成词典库

/usr/local/coreseek/mmseg3/bin/mmseg -u new_dict.txt

将生成一个文件 new_dict.txt.uni, 将该文件改名为uni.lib,完成词典的构造

Step4: 重建索引 /export/coreseek/shell/rotate_indexer.sh product main

Step5: 检查添加结果 搜索新添加的关键词,看是否被拆分


其他:
检查添加的词,哪些后面缺少了”词频“ 1
cat 717add_dict.txt | grep -v 'x:[1-9]' | awk '{print $2" "$1}' | sort | grep -v '[0-9]'
检查错行情况, x:n 是否都在偶数行
cat 717add_dict.txt | grep -n 'x:[0-9]' | awk -F ':' '{if($1%2 == 1) {print $0}}'

原文地址:https://www.cnblogs.com/bandbandme/p/4656361.html