Analysis.php 869 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @auther: xxf
  4. * Date: 2019/8/19
  5. * Time: 11:04
  6. */
  7. namespace app\common\services\wordanalysis;
  8. /**
  9. * 中文分词提取关键字
  10. */
  11. class Analysis
  12. {
  13. /**
  14. * Notes:关键字提取
  15. * @auther: xxf
  16. * Date: 2019/8/19
  17. * Time: 11:09
  18. * @param string $content
  19. * @param int $num 获取数量
  20. * @return string
  21. */
  22. public static function getKeywords($content = "",$num = 3) {
  23. if (empty ( $content )) {
  24. return '';
  25. }
  26. require_once 'phpanalysis.class.php';
  27. PhpAnalysis::$loadInit = false;
  28. $pa = new PhpAnalysis( 'utf-8', 'utf-8', false );
  29. $pa->LoadDict ();
  30. $pa->SetSource ($content);
  31. $pa->StartAnalysis ( true );
  32. $tags = $pa->GetFinallyKeywords ($num); // 获取文章中的n个关键字
  33. return $tags;//返回关键字
  34. }
  35. }