scws(simple chinese word segmentation)是一个用于中文文本分词的简单工具,主要基于双向最大匹配算法。
zhparser是一个用于中文文本解析的开源工具,它提供了中文分词、词性标注、命名实体识别等功能。zhparser使用最大匹配算法进行分词,支持多种精度设置,并且可以与其他自然语言处理工具集成使用。使用zhparser可以方便地进行中文文本的分析和处理,提高自然语言处理的准确率和效率。
scws和zhparser都是用于中文文本处理的工具,而postgresql则是一个开源的关系型数据库管理系统。在postgresql中,可以使用全文检索功能对文本数据进行高效检索。步骤如下:
1.安装scws
#下载scws并解压
wget -q -o - http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2 | tar xf -
#安装scws
cd scws-1.2.3 ; ./configure ; make install
#默认安装路径/usr/local/include/scws/
2.安装zhparser
git clone https://github.com/amutu/zhparser.git
cd zhparser
scws_home=/usr/local make&&make install
3.异常处理
#报错1:make: pg_config:命令未找到,make: *** 无目标。 停止。
解决方法:yum install postgresql-devel
#报错2:zhparser.c:15:27: 致命错误:utils/varlena.h:没有那个文件或目录。编译中断...
#缺失环境变量会报错
解决方法:export path=/opt/data/postgresql/9.5/bin:$path
#postgresql数据库如果缺失环境变量,需要手动配置,根据自己的postgresql安装路径自行修改
vim /etc/profile
export path="$path:/u/postgresql"
pg_home=/opt/data/postgresql/9.5
pg_bin=/opt/data/postgresql/9.5/bin
path=$path:$pg_bin
#使环境变量生效:
source /etc/profile
#验证配置变量是否生效:
echo $pg_home
postgresql配置中文文本解析
#创建一个名为zhparser的扩展,该扩展用于中文文本的解析
create extension zhparser;
#创建一个名为testzhcfg的文本搜索配置,该配置使用zhparser解析器。
create text search configuration testzhcfg (parser = zhparser);
#添加令牌映射,在testzhcfg配置中为小写字母a-z添加映射到simple词典。
alter text search configuration testzhcfg add mapping for a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z with simple;
#将report_content表中的content列的文本转换为tsvector类型,并使用testzhcfg配置进行中文文本的解析。然后将解析后的结果更新到content_tsv列中。
update report_content set content_tsv = to_tsvector('testzhcfg',content);
发表评论