Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5277468
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: PERL

2014-12-04 11:03:14

http://www.cnblogs.com/zhangchaoyang/articles/2034036.html


首先给Perl安装Text::Scws模块
 perl Makefile.PL LIBS='-L/usr/local/lib' INC='-I/usr/local/include/scws'  
make  
make test  
sudo make install

SCWS的Perl编程实例:
#!/usr/bin/perl
use Text::Scws;
$scws = Text::Scws->new();
$scws->set_charset('utf-8');
$scws->set_dict('/usr/local/etc/dict.utf8.xdb');
$scws->set_rule('/usr/local/etc/rules.utf8.ini');
$scws->set_ignore(1);
$scws->set_multi(1);
 
$s = shift;
$scws->send_text($s);
while ($r = $scws->get_result()) {
  foreach (@$r) {
      print $_->{word}, " ";
  }
}
print "\n";

##############################################################################################
 #!/usr/bin/perl
use Text::Scws;
$scws = Text::Scws->new();
$scws->set_charset('gbk');
$scws->set_dict('dict.xdb');
$scws->set_rule('/usr/local/etc/rules.ini');
$scws->set_ignore(0);
$scws->set_multi(1);
$s = '  以我的理解,最简单的分词程序,应该是先将中文文本切成最小的单位--汉字--再从词典里找词,将这些字按照最左最长原则(与正则精神暗合),合并为以词为单位的集合。这样的应该是最快的,只按照给定的数据划分>
合并即可,不必考虑语法元素的权重(词性:名动形数量代等等,语法:主谓宾定状补),以及上下文的出现次数。

';
$scws->send_text($s);
 while ($r = $scws->get_result()) {
foreach (@$r) {
       print $_->{word}, " ";
} }
print "\n";
阅读(911) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~