发布版本:
  httpcws 1.0.0 (最新版本:2009-08-10发布)

  程序网址:http://code.google.com/p/httpcws

  安装使用手册:http://blog.zyan.cc/httpcws_v100/

  下载地址(32位版):http://httpcws.googlecode.com/files/httpcws-1.0.0-i386-bin.tar.gz

  下载地址(64位版):http://httpcws.googlecode.com/files/httpcws-1.0.0-x86_64-bin.tar.gz

  中文分词在线演示:http://blog.zyan.cc/demo/httpcws/

  PHP演示程序下载:http://blog.zyan.cc/demo/httpcws/httpcws-php-demo.zip



  httpcws 中文简介
  1、什么是 httpcws ?
  HTTPCWS 是一款基于HTTP协议的开源中文分词系统,目前仅支持Linux系统。HTTPCWS 使用“ICTCLAS 3.0 2009共享版中文分词算法”的API进行分词处理,得出分词结果。HTTPCWS 将取代本人之前开发的 PHPCWS 中文分词扩展

  ICTCLAS(Institute of Computing Technology, Chinese Lexical Analysis System)是中国科学院计算技术研究所在多年研究工作积累的基础上,基于多层隐马模型研制出的汉语词法分析系统,主要功能包括中文分词;词性标注;命名实体识别;新词识别;同时支持用户词典。ICTCLAS经过五年精心打造,内核升级6次,目前已经升级到了ICTCLAS3.0,分词精度98.45%,各种词典数据压缩后不到3M。ICTCLAS在国内973专家组组织的评测中活动获得了第一名,在第一届国际中文处理研究机构SigHan组织的评测中都获得了多项第一名,是当前世界上最好的汉语词法分析器。

  ICTCLAS 3.0 商业版是收费的,而免费提供的 ICTCLAS 3.0 共享版不开源,词库是根据人民日报一个月的语料得出的,很多词语不存在。所以本人补充的一个19万条词语的自定义词库,对ICTCLAS分词结果进行合并处理,输出最终分词结果。

  由于 ICTCLAS 3.0 2009 共享版只支持GBK编码,因此,如果是UTF-8编码的字符串,可以先用iconv函数转换成GBK编码,再用httpcws进行分词处理,最后转换回UTF-8编码。

  HTTPCWS 软件自身(包括httpcws.cpp源文件、dict/httpcws_dict.txt自定义词库)采用NewBSD开源协议,可以自由修改。HTTPCWS 使用的 ICTCLAS 共享版 API 及 dict/Data/ 目录内的语料库,版权及著作权归中国科学院计算技术研究所、ictclas.org所有,使用需遵循其相关协议。



  2、httpcws 中文分词在线演示
  演示网址:http://blog.zyan.cc/demo/httpcws/



  3、httpcws 中文分词下载安装
  32位版:
cd /usr/local/
wget http://httpcws.googlecode.com/files/httpcws-1.0.0-i386-bin.tar.gz
tar zxvf httpcws-1.0.0-i386-bin.tar.gz
rm -f httpcws-1.0.0-i386-bin.tar.gz
cd httpcws-1.0.0-i386-bin/
ulimit -SHn 65535
/usr/local/httpcws-1.0.0-i386-bin/httpcws -d -x /usr/local/httpcws-1.0.0-i386-bin/dict/


  64位版:
cd /usr/local/
wget http://httpcws.googlecode.com/files/httpcws-1.0.0-x86_64-bin.tar.gz
tar zxvf httpcws-1.0.0-x86_64-bin.tar.gz
rm -f httpcws-1.0.0-x86_64-bin.tar.gz
cd httpcws-1.0.0-x86_64-bin/
ulimit -SHn 65535
/usr/local/httpcws-1.0.0-x86_64-bin/httpcws -d -x /usr/local/httpcws-1.0.0-x86_64-bin/dict/


  命令行启动参数:

  点击在新窗口中浏览此图片



  4、httpcws 使用方法
  GET方法(文本长度受URL的长度限制,需要分词的文本为GBK编码,最好采用urlencode对文本进行编码):


  POST方法(文本长度无限制,适用于大文本分词,需要分词的文本为GBK编码,最好采用urlencode对文本进行编码):
curl -d "有人的地方就有江湖" http://192.168.8.42:1985
curl -d "%D3%D0%C8%CB%B5%C4%B5%D8%B7%BD%BE%CD%D3%D0%BD%AD%BA%FE" http://192.168.8.42:1985


  PHP 调用 HTTPCWS 示例:

  ①、对GBK编码的字符串进行中文分词处理(HTTP POST方式):
<?php
@header('Content-Type: text/html; charset=gb2312');
$text = "有人的地方就有江湖";
$text = urlencode($text);
$opts = array(
  'http'=>array(
    'method'=>"POST",
    'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
              "Content-length:".strlen($data)."\r\n" .
              "Cookie: foo=bar\r\n" .
              "\r\n",
    'content' => $text,
  )
);
$context = stream_context_create($opts);
$result = file_get_contents("http://127.0.0.1:1985", false, $context);
echo $result;
?>


  ②、对UTF-8编码的字符串进行中文分词处理(HTTP POST方式):
<?php
@header('Content-Type: text/html; charset=utf-8');
$text = "有人的地方就有江湖";
$text = iconv("UTF-8", "GBK//IGNORE", $text);
$text = urlencode($text);
$opts = array(
  'http'=>array(
    'method'=>"POST",
    'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
              "Content-length:".strlen($data)."\r\n" .
              "Cookie: foo=bar\r\n" .
              "\r\n",
    'content' => $text,
  )
);
$context = stream_context_create($opts);
$result = file_get_contents("http://127.0.0.1:1985", false, $context);
$result = iconv("GBK", "UTF-8//IGNORE", $result);
echo $result;
?>


  ③、对GBK编码的字符串进行中文分词处理(HTTP GET方式):
<?php
@header('Content-Type: text/html; charset=gb2312');
$text = "有人的地方就有江湖";
$text = urlencode($text);
$result = file_get_contents("http://127.0.0.1:1985/?w=".$text);
echo $result;
?>


  ④、对UTF-8编码的字符串进行中文分词处理(HTTP GET方式):
<?php
@header('Content-Type: text/html; charset=utf-8');
$text = "有人的地方就有江湖";
$text = iconv("UTF-8", "GBK//IGNORE", $text);
$text = urlencode($text);
$result = file_get_contents("http://127.0.0.1:1985/?w=".$text);
$result = iconv("GBK", "UTF-8//IGNORE", $result);
echo $result;
?>




  5、httpcws 分词速度及用途

  局域网内 HTTPCWS 接口中文分词平均处理速度(Wait时间):0.001秒。HTTPCWS 基于 libevent + epoll 网络IO模型开发,经测试,每秒可处理5000~20000次请求。

  点击在新窗口中浏览此图片

  HTTPCWS 属于《[http://blog.zyan.cc/post/385.htm 亿级数据的高并发通用搜索引擎架构设计]》的一部分,用作“搜索查询接口”的关键字分词处理。在此架构中,Sphinx索引引擎对于CJK(中日韩)语言支持一元切分,假设【反恐行动是国产主视角射击网络游戏】这段文字,Sphinx会将其切成【反 恐 行 动 是 国 产 主 视 角 射 击 网 络 游 戏】,然后对每个字建立反向索引。如果用这句话中包含的字组成一个不存在的词语,例如【恐动】,也会被搜索到,所以搜索时,需要加引号,例如搜索【"反恐行动"】,就能完全匹配连在一起的四个字,不连续的【"恐动"】就不会被搜索到。但是,这样还有一个问题,搜索【"反恐行动游戏"】或【"国产网络游戏"】就会搜索不到。所以,我在搜索层写了个PHP中文分词扩展,搜索“反恐行动游戏”、“国产网络游戏”,会被httpcws中文分词函数分别切分为“反恐行动 游戏”、“国产 网络游戏”,这时候,用PHP函数给以空格分隔的词语加上引号,去搜索【"反恐行动" "游戏"】或【"国产" "网络游戏"】,就能搜索到这条记录了。由于httpcws位于搜索层,中文分词词库发生增、删、改,只需重启httpcws进程即可,无需重建搜索索引。

  根据上述情况,对于那些采用二元交叉切分的搜索引擎,httpcws用在前端搜索层对用户输入的搜索关键字、短语进行分词处理,同样适合。httpcws开发的目的正在于此,对于短句、小文本中文分词切分,速度非常之快。



  6、自定义词库
  修改dict/httpcws_dict.txt文件,可以自由增加自己需要的词语。重启httpcws即可生效。





技术大类 » 搜索引擎技术 | 评论(409) | 引用(1) | 阅读(160281)
托袜子
2013-2-15 21:59
demo代码有问题,
$opts = array(
  'http'=>array(
    'method'=>"POST",
    'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
              "Content-length:".strlen($data)."\r\n" .
              "Cookie: foo=bar\r\n" .
              "\r\n",
    'content' => $text,
  )
这段代码里的 $data 应改为 $text
词性标注应该如何使用呢?
okcvs Email
2013-3-20 17:37
这个能标注词性吗?有手册或者代码吗
加啡猫 Email Homepage
2013-8-29 13:53
连续跑一份超过100万行的数据,httpcws会崩掉。*** glibc detected *** ./httpcws: malloc(): memory corruption: 0x0000000001e2cfe0 ***======= Backtrace: =========[0x440d59][0x442858][0x41b09d][0x41b059][0x412453][0x412edb][0x40e60c][0x400947][0x4068f0][0x401b78][0x400609][0x42efb0][0x4001e9]======= Memory map: ========00400000-004d9000 r-xp 00000000 08:01 786701                             /root/httpcws-1.0.0-x86_64-bin/httpcws-1.0.0-x86_64-bin/httpcws006d9000-006db000 rw-p 000d9000 08:01 786701                             /root/httpcws-1.0.0-x86_64-bin/httpcws-1.0.0-x86_64-bin/httpcws006db000-006f3000 rw-p 00000000 00:00 0 01ddb000-02ce8000 rw-p 00000000 00:00 0 02ce8000-03a23000 rw-p 00000000 00:00 0 7f6444000000-7f6444025000 rw-p 00000000 00:00 0 7f6444025000-7f6448000000 ---p 00000000 00:00 0 7f644b779000-7f644c00c000 rw-p 00000000 00:00 0 7f644c00d000-7f644c0ce000 rw-p 00000000 00:00 0 7f644cb30000-7f644cb31000 rw-p 00000000 00:00 0 7fffda0cd000-7fffda0e2000 rw-p 00000000 00:00 0                          [stack]7fffda1ff000-7fffda200000 r-xp 00000000 00:00 0                          [vdso]ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
磨延城 Email Homepage
2013-10-21 21:06
磨途歌学习了
django Email Homepage
2013-11-30 18:56
Uggs Sale the ideal idea Coach Outlet Online  enough time to search for many of reduction Ugg boot. Like big portions? If you began ready your apartment, Coach Outlet  it's always best to consider the most effective way direct to the stage it could be to utilise your inventory throughout Coach Factory Outlet  concern, or maybe you basically won't destination stuff not enough.we're anti- whitening tray because Coach Outlet Online  i will be enjoy just get germ dog breeders
viking
2014-3-27 17:35
您好,在本机上循环请求1w次,耗时90秒,平均每秒也就100+的处理能力,跟上面给出的性能“每秒可处理5000~20000次请求”相差很多啊
c.k
2014-4-3 17:38
请问下启动时一直报ERROR: Count not open the Chinese dictionary!,要怎么处理
c.k
2014-4-3 17:38
ERROR: Count not open the Chinese dictionary!请问报此错误是什么原因,要怎么处理
Steven Email Homepage
2015-3-19 02:48
Thank you for this post Weight Loss Tea
rodrego Email Homepage
2015-3-20 22:39
Thank you for sharing this post with us asphalt 8 cheats
大海
2016-2-27 22:49
[root@localhost httpcws-1.0.0-i386-bin]# ./httpcws -x ./dict/./dict/ERROR: Count not open the Chinese dictionary!
消逝文字 Email Homepage
2016-3-13 23:54
[root@localhost httpcws-1.0.0-x86_64-bin]# ./httpcws -d -x /usr/local/httpcws-1.0.0-x86_64-bin/dict//usr/local/httpcws-1.0.0-x86_64-bin/dict/ERROR: Count not open the Chinese dictionary!你好,请教一下 请问启用httpcws报错是什么原因  还是说系统需要额外的软件包支持才能够使用? 谢谢
em
2016-4-27 13:16
你好 请问下 Count not open the Chinese dictionary!错误该怎么处理,万分感谢
sss
2016-10-22 20:48
Count not open the Chinese dictionary! 什么原因
零度先生 Email Homepage
2016-10-28 11:21
ERROR: Count not open the Chinese dictionary!  请问下这是什么原因导致的,词典文件权限已加到最大,并将dict加到了系统变量,为什么还是报找不到词典,请解答一下,谢谢
魔法涂鸦 Email
2017-1-9 20:07
ERROR: Count not open the Chinese dictionary! 我也提示这个问题,不知道怎么解决才好。
dengzi
2017-10-17 19:09
ERROR: Count not open the Chinese dictionary!
请问这个怎么解决啊,不要沉。。。
分页: 5/21 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]