: This article mainly introduces Thinkphp32 using scws Chinese word segmentation to extract keywords. if you are interested in PHP tutorials, refer to it. SCWS is the abbreviation of Simple Chinese Word Segmentation (I .e., Simple Chinese Word Segmentation system ).
1. download the class officially provided by scws (pscws version 4 is used here)
Http://www.xunsearch.com/scws/down/pscws4-20081221.tar.bz2
Download the XDB Dictionary File (utf8 simplified Chinese dictionary package is used here)
Http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
2. decompress the scws class Pscws. class. php (here I put pscws4.class. the php file name is changed to pscws. class. php) and XDB_R.class.php (here I replace the xdb_r.class.php file name with an uppercase XDB_R.class.php) under the ThinkPHP \ Library \ Org \ Util directory.
3. modify Pscws. class. php.
Add namespace
1 namespace Org\Util;
Change the class name to Pscws.
Delete require_once (dirname (_ FILE _). '/XBD_R.class.php.
Modify XDB_R.class.php
Add namespace
namespace Org\Util;
4. decompress the XDB Dictionary File
Create a dict folder under the Public \ admin directory, and then convert the dict of the XDB dictionary file. decompress utf8.xdb to the topic, and then extract the rules under etc in the scws class. put utf8.ini under this directory.
5. add a constant definition code to the entry file (which is actually the path of the definition dictionary file and configuration file)
define("CONF_PATH", dirname(__FILE__)."/Public/admin/dict/");
6. create a private method in the IndexController. class. php controller for other methods to call.
/*** Chinese word segmentation * @ params string $ the statement that the title requires word segmentation * @ params int $ num word segmentation count. the default value is **/private function get_tags ($ title, $ num = null) {$ pscws = new \ Org \ Util \ Pscws ('utf8'); $ pscws-> set_dict (CONF_PATH. 'dict. utf8.xdb '); $ pscws-> set_rule (CONF_PATH. 'rules. utf8.ini '); $ pscws-> set_ignore (true); $ pscws-> send_text ($ title); $ words = $ pscws-> get_tops ($ num ); $ pscws-> close (); $ tags = array (); foreach ($ words as $ val) {$ tags [] = $ val ['word'];} return implode (',', $ tags);}/*** product search result page **/public function search () {$ rzt = $ this-> get_tags );}
The result is as follows:
Patent leather, single shoes, pointed, high heel, new, delivery, 910033, 7.31, 39
The above introduces Thinkphp32 using scws Chinese word segmentation to extract keywords, including The require content, hope to be helpful to friends who are interested in PHP tutorials.