ankit20893/summarize-text

summarizeText (自动文本摘要) for PHP7

dev-master 2020-05-07 11:59 UTC

This package is auto-updated.

Last update: 2024-09-07 21:53:37 UTC


README

此源代码可以摘要文本,例如文章,到简短的段落。在开始摘要之前,它会删除在Stopwords命名空间中定义的垃圾词。它可以扩展到其他语言。

作者,贡献者

自动摘要

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

此实现的算法是

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

安装

composer require ankit20893/summarize-text

测试

cd project-folder
composer test

或者

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

示例

use summarizeText\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);