README
extract relevant keywords from a given text
How to use it
In order to use the class, you must instance a Config
object.
<?php require __DIR__ . "/vendor/autoload.php"; use \crodas\TextRank\Config; use \crodas\TextRank\TextRank; $config = new Config; $textrank = new TextRank($config); $keywords = $textrank->getKeywords($some_long_text); var_dump($keywords);
It is possible to get better results by adding few information about the language (stopword
list, stemmer
with pecl install stem
).
<?php require __DIR__ . "/vendor/autoload.php"; use \crodas\TextRank\Config; use \crodas\TextRank\TextRank; use \crodas\TextRank\Stopword; $config = new Config; $config->addListener(new Stopword); $textrank = new TextRank($config); $keywords = $textrank->getKeywords($some_long_text); var_dump($keywords);
By doing this it will detect the language of the text and will remove common words (from the stopword list). If ext-stem
is available the results will be even better.
Summarize large texts
This class is also capable of summarizing long texts
$config = new \crodas\TextRank\Config; $config->addListener(new \crodas\TextRank\Stopword); $analizer = new \crodas\TextRank\Summary($config); $summary = $analizer->getSummary($text);
$summary
is at most 5% of the sentences of the text.
https://packagist.org/packages/crodas/text-rank
https://github.com/crodas/TextRank
安装是重点
composer require crodas/languagedetector
composer.json 文件加 autoload内容 src/lib/ 对相应 textRank 算法目录
需要到github下载 https://github.com/crodas/TextRank
{ "require": { "crodas/languagedetector": "^0.1.1" }, "autoload": { "classmap":["src/lib/"] } }