小言_互联网的博客

PHP对接百度智能云之语言处理技术

500人阅读  评论(0)

  
  1. api地址
  2. https://cloud.baidu.com/doc/NLP/s/ 7k 6z 52ggx


  
  1. 控制台申请应用
  2. https:/ /console.bce.baidu.com/ai /?_=1619424019362&fromai=1#/ai /nlp/app /detail~appId=2431771

3、SDK下载

控制器方法:


  
  1. /*
  2. * 百度AI智能 文章自动打标签
  3. * 2021-4-26 16:45:06
  4. */
  5. public function autoTags(Request $request)
  6. {
  7. $this->validate($request, [
  8. 'id' => 'required',
  9. //'title' => 'required',
  10. //'content' => 'required'
  11. ],
  12. [
  13. 'id.required' => '请传递文章id',
  14. //'title.required' => '请传递文章标题',
  15. //'content.required' => '请传递文章内容'
  16. ]);
  17. $APP_ID = '24068588';
  18. $API_KEY = 'GgpkkpSLPyqUzXhVoaCNIrZQ';
  19. $SECRET_KEY = 'NZzGpb8hQEnXD94U2yefdugvyBtWBbsj';
  20. $client = new \App\Expands\Baidu\Ocr\AipNlp($APP_ID, $API_KEY, $SECRET_KEY);
  21. $article = ArticleModel::where( 'id',$request[ 'id'])->select( '*')->first();
  22. //dd($article);
  23. // 可选参数
  24. $options = array();
  25. $options[ "language_type"] = "CHN_ENG";
  26. $options[ "detect_direction"] = "true";
  27. $options[ "detect_language"] = "true";
  28. $options[ "probability"] = "true";
  29. // 调用通用文字识别, 图片参数为远程url图片
  30. echo '标题: '.$article->title;
  31. echo '<hr>';
  32. echo '内容: '. (strip_tags($article->body));
  33. $title = mb_substr( $article->title, 0, 40 );
  34. $content = mb_substr( strip_tags($article->body), 0, 32000 );
  35. //;
  36. $res = $client->keyword($title, $content);
  37. dd($res);
  38. return [ 'code' => 0, 'data'=>$res];
  39. }

api调用测试:

 

 


转载:https://blog.csdn.net/php_xml/article/details/116161643
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场