Installation and Use of SCWS in open-source php Chinese Word Segmentation System

Source: Internet
Author: User
This article describes how to install and use SCWS, an open-source php Chinese word segmentation system. For more information about how to install and use SCWS, see the following article, for more information, see

1. Introduction to SCWS

SCWS is the abbreviation of Simple Chinese Word Segmentation (I .e., Simple Chinese Word Segmentation System ).
This is a mechanical Chinese Word Segmentation engine based on the Word Frequency dictionary. It can divide a full range of Chinese text into words. Words are the smallest unit of Chinese characters, but they are not separated by spaces in English. Therefore, it is difficult to accurately and quickly word segmentation.
SCWS is developed in pure C language and does not rely on any external library function. Dynamic Link Library can be directly used to embed the application. supported Chinese encoding include GBK and UTF-8. In addition, the PHP extension module is provided to quickly and conveniently use Word Segmentation in PHP.
The word segmentation algorithm does not have many innovative components. It uses a Word Frequency dictionary collected by itself, supplemented by some proprietary names, personal names, place names, digital ages, and other rules to achieve basic word segmentation, the accuracy of small-scale tests is between 90% and ~ Between 95% can basically meet the needs of some small search engines, keyword extraction and other occasions. The first prototype was released at the end of 2005.
SCWS was developed by hightman and released open-source with the BSD license protocol. The source code is hosted on github.

Ii. scws Installation

The Code is as follows:

# wget -c https://www.php1.cn/# tar jxvf scws-1.2.1.tar.bz2# cd scws-1.2.1# ./configure --prefix=/usr/local/scws# make && make install

Iii. scws PHP extension Installation

The Code is as follows:

# 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

Iv. dictionary Installation

The Code is as follows:

# wget https://www.php1.cn/# tar jxvf scws-dict-chs-utf8.tar.bz2 -C /usr/local/scws/etc/# chown www:www /usr/local/scws/etc/dict.utf8.xdb

V. php instance code. For details, refer to the official scws api description.

The Code is as follows:

// Instantiate the core class of the Word Segmentation plug-in $ so = scws_new (); // sets the encoding used for word segmentation $ so-> set_charset ('utf-8 '); // set the dictionary used for word segmentation (utf8 dictionary is used here) $ so-> set_dict ('/usr/local/scws/etc/dict. utf8.xdb '); // set the rule for word segmentation $ so-> set_rule ('/usr/local/scws/etc/rules. utf8.ini '); // remove the punctuation mark $ so-> set_ignore (true) before word segmentation; // whether to perform multiple segmentation, for example, "Chinese" returns the word "China + People + Chinese. $ So-> set_multi (true); // set to automatically aggregate text by two-word segmentation $ so-> set_duality (true ); // statement $ so-> send_text ("Welcome to IT development in the fire age"); // obtain the word segmentation result, if you use the get_tops method to extract high-frequency words while ($ tmp = $ so-> get_result () {print_r ($ tmp) ;}$ so-> close ();


Description of returned array results:

The Code is as follows:

Word _ string _ idf _ float _ inverse text word frequency off _ int _ Position of the word in the original text path attr _ string _ part of speech

Vi. Online APIs

You can also use online APIs to perform Chinese word segmentation. The API address is http://www.xunsearch.com/scws/api.php. The detailed description is also in the address.

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.