Home > Backend Development > PHP Problem > What is the method for php to use PHPAnalysis to extract Chinese word segmentation of keywords?

What is the method for php to use PHPAnalysis to extract Chinese word segmentation of keywords?

醉折花枝作酒筹
Release: 2023-03-10 06:32:02
forward
2168 people have browsed it

This article will introduce to you how PHP uses PHPAnalysis to extract Chinese word segmentation of keywords. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is the method for php to use PHPAnalysis to extract Chinese word segmentation of keywords?

Requirements: When doing SEO keywords, you need to extract keywords from the title or text

1. PHPAnalysis download address

http://www.phpbone.com/phpanalysis/#api

The original download address cannot be opened and has been uploaded to github

https://github.com/ feixuekeji/PHPAnalysis

After downloading, unzip and place it in the extend directory (tp5 is used as an example, other directories are also acceptable)

2. Encapsulation

<?php
/**
 * @auther: xxf
 * Date: 2019/8/19
 * Time: 11:04
 */
 
namespace WordAnalysis;
 
/**
 * 中文分词提取关键字
 */
class Analysis
{
    /**
     * Notes:关键字提取
     * @auther: xxf
     * Date: 2019/8/19
     * Time: 11:09
     * @param string $content
     * @param int $num 获取数量
     * @return string
     */
    public static function getKeywords($content = "",$num = 3) {
        if (empty ( $content )) {
            return &#39;&#39;;
        }
 
        require_once &#39;phpanalysis.class.php&#39;;
 
 
        \PhpAnalysis::$loadInit = false;
        $pa = new \PhpAnalysis ( &#39;utf-8&#39;, &#39;utf-8&#39;, false );
        $pa->LoadDict ();
        $pa->SetSource ($content);
        $pa->StartAnalysis ( true );
 
        $tags = $pa->GetFinallyKeywords ($num); // 获取文章中的n个关键字
        return $tags;//返回关键字
    }
 
}
Copy after login

Use

$data[&#39;seo&#39;][&#39;keyword&#39;] = Analysis::getKeywords($article_info[&#39;title&#39;]);
Copy after login

Recommended learning: php video tutorial

The above is the detailed content of What is the method for php to use PHPAnalysis to extract Chinese word segmentation of keywords?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template