[Php] & lt ;? Php/*** Chinese word segmentation processing method * + ----------------------------------- * @ paramstirng $ string the string to be processed * @ paramboolers $ sort = false returns in descending order of value * @ paramNumbers $ top = 0 specify
[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 '));