Chinese word segmentation processing method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Chinese word segmentation processing method. [Php]? Php *** Chinese word segmentation processing method * + ----------------------------------- * @ paramstirng $ string to be processed * @ paramboolers $ sortfalse reverse order based on value * @ [php]

/**
* Chinese word segmentation
* + ---------------------------------
* @ Param stirng $ string the string to be processed
* @ Param boolers $ sort = false reverse order based on value
* @ Param Numbers $ top = 0 return the specified quantity. by default, all are returned.
* + ---------------------------------
* @ Return void
*/
Function scws ($ text, $ top = 5, $ return_array = false, $ sep = ','){
Include ('./pscws4/pscws4.php'); // download pscws4 from the URL below
$ Cws = new pscws4 ('utf-8 ');
$ Cws-> set_charset ('utf-8 ');
$ Cws-> set_dict ('./pscws4/etc/dict. utf8.xdb ');
$ Cws-> set_rule ('./pscws4/etc/rules. utf8.ini ');
// $ Cws-> set_multi (3 );
$ Cws-> set_ignore (true );
// $ Cws-> set_debug (true );
// $ Cws-> set_duality (true );
$ Cws-> send_text ($ text );
$ Ret = $ cws-> get_tops ($ top, 'R, v, P ');
$ Result = null;
Foreach ($ ret as $ value ){
If (false ===$ return_array ){
$ Result. = $ sep. $ value ['word'];
} Else {
$ Result [] = $ value ['word'];
}
}
Return false ===$ return_array? Substr ($ result, 1): $ result;
}
Print_r (scws ('qinghua Yunlong incense burner '));

/**
* Chinese word segmentation
* + ---------------------------------
* @ Param stirng $ string the string to be processed
* @ Param boolers $ sort = false reverse order based on value
* @ Param Numbers $ top = 0 return the specified quantity. by default, all are returned.
* + ---------------------------------
* @ Return void
*/
Function scws ($ text, $ top = 5, $ return_array = false, $ sep = ','){
Include ('./pscws4/pscws4.php'); // download pscws4 from the URL below
$ Cws = new pscws4 ('utf-8 ');
$ Cws-> set_charset ('utf-8 ');
$ Cws-> set_dict ('./pscws4/etc/dict. utf8.xdb ');
$ Cws-> set_rule ('./pscws4/etc/rules. utf8.ini ');
// $ Cws-> set_multi (3 );
$ Cws-> set_ignore (true );
// $ Cws-> set_debug (true );
// $ Cws-> set_duality (true );
$ Cws-> send_text ($ text );
$ Ret = $ cws-> get_tops ($ top, 'R, v, P ');
$ Result = null;
Foreach ($ ret as $ value ){
If (false ===$ return_array ){
$ Result. = $ sep. $ value ['word'];
} Else {
$ Result [] = $ value ['word'];
}
}
Return false ===$ return_array? Substr ($ result, 1): $ result;
}
Print_r (scws ('qinghua Yunlong incense burner '));


Why? Php/*** Chinese word segmentation processing method * + ----------------------------------- * @ param stirng $ string the string to be processed * @ param boolers $ sort = false reverse order based on value *@...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.