form1.cn
Make a little progress every day

Linux编译安装SCWS中文分词系统

07th of March 2017 Linux Sphinx 2265

简介

    SCWS 是 Simple Chinese Word Segmentation 的首字母缩写(即:简易中文分词系统)。

    这是一套基于词频词典的机械式中文分词引擎,它能将一整段的中文文本基本正确地切分成词。 词是中文的最小语素单位,但在书写时并不像英语会在词之间用空格分开, 所以如何准确并快速分词一直是中文分词的攻关难点。

    SCWS 采用纯 C 语言开发,不依赖任何外部库函数,可直接使用动态链接库嵌入应用程序, 支持的中文编码包括 GBK、UTF-8 等。此外还提供了 PHP 扩展模块, 可在 PHP 中快速而方便地使用分词功能。

    分词算法上并无太多创新成分,采用的是自己采集的词频词典,并辅以一定的专有名称,人名,地名, 数字年代等规则识别来达到基本分词,经小范围测试准确率在 90% ~ 95% 之间, 基本上能满足一些小型搜索引擎、关键字提取等场合运用。首次雏形版本发布于 2005 年底。


安装说明

# wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2  //下载scws
# tar xvjf scws-1.2.3.tar.bz2  //解压
# cd scws-1.2.3  //进入目录
# ./configure --prefix=/usr/local/scws12  //configure操作
# make
# make install


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

常用选项为:--prefix=<scws的安装目录>


顺利的话已经编译并安装成功到 /usr/local/scws 中了,执行下面命令看看文件是否存在

# ls -al /usr/local/scws/lib/libscws.la


试试执行 scws-cli 文件

# /usr/local/scws/bin/scws -h
scws (scws-cli/1.2.3)
Simple Chinese Word Segmentation - Command line usage.
Copyright (C)2007 by hightman.
Usage: scws [options] [input] [output]
  -i <file|string> input string or filepath 
                   (default: try to read from <stdin> everyline)
  -o <file>        output filepath (default to <stdout>)
  -c <charset>     set the charset (default: gbk)
                   charset must been same with dictionary & ruleset
  -r <file>        set the ruleset file (default: none)
  -d <file>        set the dictionary file[s] (default: none)
                   if there are multi files, split filepath use ':'
                   if the file suffix is .txt, it will be treated as plain text dict.
  -M <1~15>        use multi child words mode(中国人->中国+人+中国人)
                   1|2|4|8: short|duality|zmain|zall
  -I               ignore the all mark symbol such as ,:
  -A               show the word attribute
  -E               import the xdb dict into xtree(memory)
  -N               don't show time usage and warnings
  -D               debug segment, see the segment detail
  -U               use duality algorithm for single chinese
  -t <NUM>         fetch the top words instead of segment
  -a [~]<attr1,attr2,...>   prefix by ~ means exclude them.
                   For topwords, exclude or include some word attrs
  -v        Show the version.
  -h        Show this page for help.
Report bugs to <hightman2@yahoo.com.cn>


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

# cd /usr/local/scws/etc
# wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2
# wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
# tar xvjf scws-dict-chs-gbk.tar.bz2
# tar xvjf scws-dict-chs-utf8.tar.bz2


这样就好顺利安装完毕可以使用 libscws 这套 C-API 了


Linux中php安装SCWS扩展

PHP扩展方式使用scws中文分词