我现在系统中要用到中文分词,从网上找到了scws中文分词系统,用的PSCWS4版本,下载之后写了个测试程序如下:
// 加入头文件
require 'pscws/pscws4.class.php';
header("Content-Type:text/html;charset=utf-8");
// 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变
$pscws = new PSCWS4('utf-8');$pscws->set_ignore('yes');
$pscws->set_dict('E:/scws/etc/dict.utf8.xdb');
$pscws->set_rule('E:/scws/etc/rules_cht.utf8.ini');// 分词调用 send_text() 将待分词的字符串传入, 紧接着循环调用 get_result() 方法取回一系列分好的词
// 直到 get_result() 返回 false 为止
// 返回的词是一个关联数组, 包含: word 词本身, idf 逆词率(重), off 在text中的偏移, len 长度, attr 词性
//
$text = "中国航天官员应邀到美国与太空总署官员开会";
$pscws->send_text($text);
while ($some = $pscws->get_result())
{
foreach ($some as $word)
{
echo $word['word'].'=>'.$word['attr'].'<br>'; }
flush();
}
$pscws->close();?>网页上的显示结果却是:
航天=>nr
?员庽>nr
?员=>nr
// 加入头文件
require 'pscws/pscws4.class.php';
header("Content-Type:text/html;charset=utf-8");
// 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变
$pscws = new PSCWS4('utf-8');$pscws->set_ignore('yes');
$pscws->set_dict('E:/scws/etc/dict.utf8.xdb');
$pscws->set_rule('E:/scws/etc/rules_cht.utf8.ini');// 分词调用 send_text() 将待分词的字符串传入, 紧接着循环调用 get_result() 方法取回一系列分好的词
// 直到 get_result() 返回 false 为止
// 返回的词是一个关联数组, 包含: word 词本身, idf 逆词率(重), off 在text中的偏移, len 长度, attr 词性
//
$text = "中国航天官员应邀到美国与太空总署官员开会";
$pscws->send_text($text);
while ($some = $pscws->get_result())
{
foreach ($some as $word)
{
echo $word['word'].'=>'.$word['attr'].'<br>'; }
flush();
}
$pscws->close();?>网页上的显示结果却是:
航天=>nr
?员庽>nr
?员=>nr
print_r($some)
的结果
=>
$pscws = new PSCWS4();
$pscws->set_charset("utf-8");
见源码 // 构造函数
function PSCWS4($charset = 'gbk')
{
$this->_xd = false;
$this->_rs = $this->_rd = array();
$this->set_charset($charset);
} // FOR PHP5
function __construct() { $this->PSCWS4(); }呵呵,明白了吧
1) 新增功能: 支持载入纯文本词典(TXT), 一次分词可使用多个词典, 以实现不改变核心词库的原则下快速增减词。
可知,应该是支持的
中文的资料你都自己不查一下.
太懒了.
if (!isset($_SERVER['argv'][1]) || !is_file($_SERVER['argv'][1]))
{
echo "Usage: {$_SERVER['argv'][0]} <xdb file> [output file]\n";
exit(0);
}$output = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'php://stdout';'argv'
Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.