nanhh/textrank

TextRank (自动文本摘要) 用于 PHP7 和 HHVM。

dev-main 2022-12-20 08:41 UTC

This package is auto-updated.

Last update: 2024-09-20 12:26:57 UTC


README

TextRank

此源代码是 TextRank 算法(自动摘要)在 PHP7 严格模式下的实现。它可以摘要文本,例如文章,成为一个简短的段落。在开始摘要之前,它会移除在 Stopwords 命名空间中定义的垃圾词。它可以扩展以支持其他语言。

TextRank 或 自动摘要

自动摘要是指通过计算机程序减少文本文档的过程,以创建一个摘要,该摘要保留了原始文档的最重要内容。能够制作连贯摘要的技术会考虑长度、写作风格和语法等变量。自动数据摘要属于机器学习和数据挖掘的一部分。摘要的主要思想是找到包含整个数据集信息的代表子集。摘要技术在当今工业的许多领域中都有应用。- 维基百科

此实现的算法是

  • 找到句子,
  • 移除停用词,
  • 通过查找和计数匹配的单词来创建整数值,
  • 通过相关单词的整数值来改变整数值,
  • 归一化值以创建分数,
  • 按分数排序

安装

composer require php-science/textrank

测试

cd project-folder
composer test

或者

cd project-folder
phpunit --colors='always' $(pwd)/tests

示例

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);

更多示例

作者,贡献者