Home > php教程 > PHP源码 > body text

php实现中文分词的例子

WBOY
Release: 2016-06-08 17:22:31
Original
1347 people have browsed it

有很多的cms都有分词的功能,多数都是用于tag标签中,本人自己写了一个分词的方式,没有强大的词库,在网上下载了一个词库和一个分词的代码

<script>ec(2);</script>

将词库和代码结合加以调试实现了中文分词..功能不是很强大高手不喜勿喷....。将实现后的代码分享给大家

 代码如下 复制代码

function get_keywords_str($content='')
{
require('./phpanalysis.class.php');
$pa = new PhpAnalysis('utf-8', 'utf-8', false);
$pa->LoadDict();//载入
$pa->SetSource($content);//将要分开的内容传入
$pa->StartAnalysis(false);
$tags = $pa->GetFinallyResult(',',6);//分词样式是以逗号分开/分词长度
return $tags; www.111cn.net
}
$str="李世民是唐朝的第二任皇帝";
echo "分词前:".$str."
";
echo "分词后:".get_keywords_str($str);
?>

全部分词源码下载地址:http://www.111cn.net//demo/fenci.rar

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!