Table of Contents
Thinkphp3.2使用scws中文分词 提取关键词,
Home php教程 php手册 Thinkphp3.2使用scws中文分词 提取关键词,

Thinkphp3.2使用scws中文分词 提取关键词,

Jun 13, 2016 am 08:52 AM
thinkphp3.2 Chinese use Key words Participle extract

Thinkphp3.2使用scws中文分词 提取关键词,

SCWS 是 Simple Chinese Word Segmentation 的首字母缩写(即:简易中文分词系统)。
1.下载scws官方提供的类(这里使用的是pscws第四版的)
http://www.xunsearch.com/scws/down/pscws4-20081221.tar.bz2
下载XDB 词典文件 (这里使用的是utf8简体中文词典包)
http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
2.解压scws类Pscws.class.php(这里我把pscws4.class.php文件名换成了pscws.class.php)和XDB_R.class.php(这里我把xdb_r.class.php文件名换成了大写的XDB_R.class.php)放到ThinkPHP\Library\Org\Util目录下面。
3.然后修改Pscws.class.php
加入命名空间

<span>1</span> namespace Org\Util;
Copy after login

将类的名称改为Pscws

把require_once (<span>dirname</span>(<span>__FILE__</span>) . '/XBD_R.class.php');这段代码删除掉。
Copy after login

修改XDB_R.class.php
加入命名空间

namespace Org\Util;
Copy after login

4.解压XDB 词典文件
在Public\admin目录下新建一个dict文件夹,然后将XDB 词典文件的dict.utf8.xdb解压到词目录下,再把scws类中的etc下面的rules.utf8.ini放到此目录下面。
5.在入口文件加入一行常量定义代码(其实就是定义词典文件和配置文件的路径)

<span>define</span>("CONF_PATH", <span>dirname</span>(<span>__FILE__</span>)."/Public/admin/dict/");
Copy after login

6.在IndexController.class.php控制器里面建立一个私有方法,供其他方法调用

 <span>/*</span><span>*
     * 中文分词  
         * @params string $title 需要分词的语句 
         * @params int $num  分词个数,默认不用填写
     *</span><span>*/</span>
    <span>private</span> <span>function</span> get_tags(<span>$title</span>,<span>$num</span>=<span>null</span><span>){        
        </span><span>$pscws</span> = <span>new</span> \Org\Util\Pscws('utf8'<span>);
        </span><span>$pscws</span>->set_dict(CONF_PATH . 'dict.utf8.xdb'<span>);
        </span><span>$pscws</span>->set_rule(CONF_PATH . 'rules.utf8.ini'<span>);
        </span><span>$pscws</span>->set_ignore(<span>true</span><span>);
        </span><span>$pscws</span>->send_text(<span>$title</span><span>);
        </span><span>$words</span> = <span>$pscws</span>->get_tops(<span>$num</span><span>);
        </span><span>$pscws</span>-><span>close();
        </span><span>$tags</span> = <span>array</span><span>();
        </span><span>foreach</span> (<span>$words</span> <span>as</span> <span>$val</span><span>) {
            </span><span>$tags</span>[] = <span>$val</span>['word'<span>];
        }
        </span><span>return</span> <span>implode</span>(',', <span>$tags</span><span>);
    }
      </span><span>/*</span><span>*
     * 商品搜索结果页
     *</span><span>*/</span>
    <span>public</span> <span>function</span><span> search(){
        </span><span>$rzt</span>=<span>$this</span>->get_tags("新款 牛漆皮小尖头直跟高跟单鞋910033 灰羊猄(7.31发货) 39"<span>);
        </span><span>print_r</span>(<span>$rzt</span><span>);
    }</span>
Copy after login

显示的结果为:

漆皮,单鞋,尖头,高跟,新款,发货,910033,7.31,39
Copy after login

 

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust aperture on Xiaomi Mi 14 Ultra? How to adjust aperture on Xiaomi Mi 14 Ultra? Mar 19, 2024 am 09:01 AM

Adjusting the aperture size has a crucial impact on the photo effect. Xiaomi Mi 14 Ultra provides unprecedented flexibility in camera aperture adjustment. In order to allow everyone to adjust the aperture smoothly and realize the free adjustment of the aperture size, the editor here brings you a detailed tutorial on how to set the aperture on Xiaomi Mi 14Ultra. How to adjust the aperture on Xiaomi Mi 14Ultra? Start the camera, switch to &quot;Professional Mode&quot;, and select the main camera - W lens. Click on the aperture, open the aperture dial, A is automatic, select f/1.9 or f/4.0 as needed.

How to set Chinese in Call of Duty: Warzone mobile game How to set Chinese in Call of Duty: Warzone mobile game Mar 22, 2024 am 08:41 AM

Call of Duty Warzone is a newly launched mobile game. Many players are very curious about how to set the language of this game to Chinese. In fact, it is very simple. Players only need to download the Chinese language pack, and then You can modify it after using it. The detailed content can be learned in this Chinese setting method introduction. Let us take a look together. How to set the Chinese language for the mobile game Call of Duty: Warzone 1. First enter the game and click the settings icon in the upper right corner of the interface. 2. In the menu bar that appears, find the [Download] option and click it. 3. Select [SIMPLIFIEDCHINESE] (Simplified Chinese) on this page to download the Simplified Chinese installation package. 4. Return to the settings

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

How to update Honor MagicOS 8.0 on Honor 90 GT? How to update Honor MagicOS 8.0 on Honor 90 GT? Mar 18, 2024 pm 06:46 PM

Honor 90GT is a cost-effective smartphone with excellent performance and excellent user experience. However, sometimes we may encounter some problems, such as how to update Honor MagicOS8.0 on Honor 90GT? This step may be different for different mobile phones and different models. So, let us discuss how to upgrade the system correctly. How to update Honor MagicOS 8.0 on Honor 90GT? According to news on February 28, Honor today pushed the MagicOS8.0 public beta update for its three mobile phones 90GT/100/100Pro. The package version number is 8.0.0.106 (C00E106R3P1) 1. Ensure your Honor The battery of the 90GT is fully charged;

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

See all articles