iankov/keywords

此包的最新版本(v1.0.0)没有提供许可证信息。

从给定文本中自动提取关键词

v1.0.0 2018-07-24 11:11 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:42:07 UTC


README

此包对相似词进行分组和计数。文本中使用最频繁的词用于构建关键词 $keywords->string($wordsCount, $delimiter)

$keywords = new Keywords;

$keywords->config([
    'min_keyword_length' => 3, //ignore words with length less then 3
    'min_keyword_similarity' => 80, //group similar words with similarity at least 80%
    'encoding' => 'utf-8' //text encoding
]);

$keywords->content($text_or_html); //set text or html which would be scanned for keywords

$keywords->content(); //get content

$keywords->ignore($string, $type); //ignore $string of $type(word, symbol, regex) from content
$keywords->ignoreWord('are'); //ignore word
$keywords->ignoreSymbol('@'); //ignore symbol
$keywords->ignoreRegex('/[0-9]+/i'); //ignore regex

$keywords->replace('/halo/i', 'hello'); //replace

$keywords->generate(); //generate keywords

$keywords->get(); //get Collection of keywords (not sorted)
$keywords->string(10, ' '); //get 10 most used keywords as a string separated by space

还可以使用函数链

$keywords = new Keywords;
$stringOfKeywords = $keywords->content($text_or_html)->generate()->string(20);

$collectionOfKeywords = (new Keywords)->content($text)->ignoreWord(['hello', 'world'])->generate()->get();