php-science / textrank
PHP的TextRank(自动文本摘要)
1.2.3
2023-12-29 15:21 UTC
Requires
- php: >=7.2
- ext-ctype: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: 9.*
This package is auto-updated.
Last update: 2024-08-29 17:02:39 UTC
README
TextRank
此源代码是PHP编程语言中TextRank算法的实现,遵循MIT许可。
TextRank与ChatGPT
ChatGPT等GPT模型是监督语言模型,能够理解上下文,并使用大量资源从给定输入生成新内容,而TextRank是一种成本低/低成本的文本提取算法。TextRank算法还可以用作GPT模型的预处理器,以减少文本大小以节省资源消耗。
TextRank或自动摘要
自动摘要是指使用计算机程序减少文本文档的过程,以创建一个保留原始文档最重要点的摘要。能够制作连贯摘要的技术会考虑诸如长度、写作风格和语法等变量。自动数据摘要属于机器学习和数据挖掘的一部分。摘要的主要思想是找到包含整个数据集信息的代表性子集。摘要技术目前在工业界的许多部门中得到广泛应用。- 维基百科
本实现算法
- 提取句子
- 移除停用词
- 通过查找和计数匹配词,为单词添加整数值
- 加权单词值
- 归一化值以获得分数
- 按分数排序
安装以在项目中使用
cd your-project-folder
composer require php-science/textrank
安装以贡献
cd git-project-folder
docker-compose build
docker-compose up -d
composer install
composer test
示例
use PhpScience\TextRank\Tool\StopWords\English; // String contains a long text, see the /res/sample1.txt file. $text = "Lorem ipsum..."; $api = new TextRankFacade(); // English implementation for stopwords/junk words: $stopWords = new English(); $api->setStopWords($stopWords); // Array of the most important keywords: $result = $api->getOnlyKeyWords($text); // Array of the sentences from the most important part of the text: $result = $api->getHighlights($text); // Array of the most important sentences from the text: $result = $api->summarizeTextBasic($text);
更多示例