Today found a very useful Chinese word segmentation tool. Share
CWS is the initials of simple Chinese word segmentation (that is, a simplified Chinese word segmentation system).
This is a mechanical Chinese word segmentation engine based on word frequency dictionary, it can cut a whole paragraph of Chinese text into words basically correctly. The word is the smallest morpheme unit in Chinese, but when writing is not like English will be separated by space between the words, so how accurate and fast participle has always been a difficult task in Chinese word segmentation.
SCWS uses the pure C language development, does not rely on any external library function, may directly use the dynamic link library to embed the application, the support Chinese code includes GBK, UTF-8 and so on. In addition, PHP expansion module is provided, which can be used quickly and conveniently in PHP.
Word segmentation algorithm does not have too many innovative components, the use of their own collection of word frequency dictionary, supplemented by a certain number of proprietary names, names, place names, digital age and other rules to achieve the basic participle, by a small range of testing accuracy rate between 90% ~ 95%, basically can meet some small search engine, keyword extraction and other occasions to use. The first prototype version was released at the end of 2005.
Second, SCWS installation
# wget-c HTTP://WWW.XUNSEARCH.COM/SCWS/DOWN/SCWS-1.2.1.TAR.BZ2
# tar JXVF scws-1.2.1.tar.bz2
# CD scws-1.2.1
#./configure--PREFIX=/USR/LOCAL/SCWS
# Make && make install
Three, Scws PHP extended Installation
# CD./phpext
# phpize
#./configure--with-php-config=/usr/local/php5410/bin/php-config
# Make && make install
# echo ' [Scws] ' >>/usr/local/php5410/etc/php.ini
# echo "extension = scws.so" >>/usr/local/php5410/etc/php.ini
# echo "Scws.default.charset = utf-8" >>/usr/local/php5410/etc/php.ini
# echo "Scws.default.fpath =/usr/local/scws/etc/" >>/usr/local/php5410/etc/php.ini
Four, the word storehouse installs
# wget HTTP://WWW.XUNSEARCH.COM/SCWS/DOWN/SCWS-DICT-CHS-UTF8.TAR.BZ2
# tar JXVF scws-dict-chs-utf8.tar.bz2-c/usr/local/scws/etc/
# chown Www:www/usr/local/scws/etc/dict.utf8.xdb
Example
<?php
Header ("content-type:text/html; Charset=utf-8 ");
Define (' App_root ', str_replace (' \ \ ', '/', dirname (__file__));
$test = ' Really afraid that one day we will once again become the intersection line, I think then can no longer return, happiness is always take the pain to do the price, you now how happy, how happy, you will be more sad more sad, do not want to happen! '
function Get_tags_arr ($title)
{
Require (app_root. ') /pscws4.class.php ');
$PSCWS = new PSCWS4 ();
$pscws->set_dict (app_root. ') /scws/dict.utf8.xdb ');
$pscws->set_rule (app_root. ') /scws/rules.utf8.ini ');
$pscws->set_ignore (TRUE);
$pscws->send_text ($title);
$words = $pscws->get_tops (5);
$tags = Array ();
foreach ($words as $val) {
$tags [] = $val [' word '];
}
$pscws->close ();
return $tags;
}
Print_r (Get_tags_arr ($test));
function Get_keywords_str ($content) {
Require (app_root. ') /phpanalysis.class.php ');
Phpanalysis:: $loadInit = false;
$pa = new Phpanalysis (' Utf-8 ', ' utf-8 ', false);
$pa->loaddict ();
$pa->setsource ($content);
$pa->startanalysis (FALSE);
$tags = $pa->getfinallyresult ();
return $tags;
}
Print (Get_keywords_str ($test));