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

中文分词API

PHP中文网
Release: 2016-05-25 17:05:02
Original
1735 people have browsed it

中文分词工具,利用新浪sae平台的分词功能,开发的简单的分词API供大家免费使用!
方法
http://5.tbip.sinaapp.com/api.php?str=明天星期天&type=str
参数说明
str = 中文字符串(要分词的中文)
type =默认返回序列化后的数组
       str  返回用,分隔的字符串 例如:明天,星期天 
       json 返回json结果

<?php
$str=$_GET[&#39;str&#39;];
$type=$_GET[&#39;type&#39;];
$seg = new SaeSegment();
       $ret = $seg->segment($str, 1);
if($type=="str"){
 
    foreach($ret as $v)
    {
        $keyword[]=$v[&#39;word&#39;];
    }print_r(implode(",",$keyword));
}else if($type=="json")
{
print_r(json_encode($ret));
}else{
print_r(serialize($ret));
}       
 // 失败时输出错误码和错误信息
if ($ret === false)
var_dump($seg->errno(), $seg->errmsg());
?>
Copy after login

                   

 以上就是中文分词API的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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