Home > Backend Development > PHP Tutorial > Share a PHP Chinese word segmentation_PHP tutorial

Share a PHP Chinese word segmentation_PHP tutorial

WBOY
Release: 2016-07-13 10:38:40
Original
903 people have browsed it


 

  1.   
  2. /**
  3. * Chinese word segmentation processing method
  4. *+---------------------------------
  5. * @param string $string The string to be processed
  6. * @param boolers $sort=false perform reverse order according to value
  7. * @param Numbers $top=0 returns the specified number, and returns all by default
  8. *+---------------------------------
  9. * @return void
  10. ​*/  
  11. function scws($text, $top = 5, $return_array = false, $sep = ',') {  
  12.     include('./pscws4/pscws4.php');//去下面给的网址把pscws4下载下来  
  13.     $cws = new pscws4('utf-8');  
  14.     $cws -> set_charset('utf-8');  
  15.     $cws -> set_dict('./pscws4/etc/dict.utf8.xdb');  
  16.     $cws -> set_rule('./pscws4/etc/rules.utf8.ini');  
  17.     //$cws->set_multi(3);  
  18.     $cws -> set_ignore(true);  
  19.     //$cws->set_debug(true);  
  20.     //$cws->set_duality(true);  
  21.     $cws -> send_text($text);  
  22.     $ret = $cws -> get_tops($top, 'r,v,p');  
  23.     $result = null;  
  24.     foreach ($ret as $value) {  
  25.         if (false === $return_array) {  
  26.             $result .= $sep . $value['word'];  
  27.         } else {  
  28.             $result[] = $value['word'];  
  29.         }  
  30.     }  
  31.     return false === $return_array ? substr($result, 1) : $result;  
  32. }  
  33. print_r(scws('青花夔龙纹香炉'));  
  34.  

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735068.htmlTechArticle?php /** *中文分词处理方法 *+--------------------------------- *@paramstirng$string要处理的字符串 *@paramboolers$sort=false根据value进行倒序 *@paramNumbers$top...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template