从文本 php 中提取关键字

我正在尝试从使用所见即所得的描述输入中提取相关关键字,使用多语言英语/阿拉伯语......使用以下功能,但它没有完成我想要的任务。看看我正在使用的功能:


   function extractKeyWords($string) {


     mb_internal_encoding('UTF-8');

     $stopwords = array();

     $string = preg_replace('/[\pP]/u', '', trim(preg_replace('/\s\s+/iu', '', mb_strtolower($string))));

     $matchWords = array_filter(explode(' ',$string) , function ($item) use ($stopwords) { return !($item == '' || in_array($item, $stopwords)

 || mb_strlen($item) <= 2 || is_numeric($item));});

     $wordCountArr = array_count_values($matchWords);

     // <p><p>


     arsort($wordCountArr);

     return array_keys(array_slice($wordCountArr, 0, 10));   }


MMTTMM
浏览 106回答 2
2回答

跃然一笑

弄清楚了 !谢谢function generateKeywords($str)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $min_word_length = 3;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $avoid = ['the','to','i','am','is','are','he','she','a','an','and','here','there','can','could','were','has','have','had','been','welcome','of','home','&nbsp;','&ldquo;','words','into','this','there'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $strip_arr = ["," ,"." ,";" ,":", "\"", "'", "“","”","(",")", "!","?"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $str_clean = str_replace( $strip_arr, "", $str);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $str_arr = explode(' ', $str_clean);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $clean_arr = [];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach($str_arr as $word)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(strlen($word) > $min_word_length)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $word = strtolower($word);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!in_array($word, $avoid)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $clean_arr[] = $word;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return implode(',', $clean_arr);&nbsp; &nbsp; &nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP