成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

HarmonyOS AI基礎(chǔ)技術(shù)賦能之關(guān)鍵字獲取

開發(fā) OpenHarmony
關(guān)鍵字提取主要用于從新聞和郵件里提取出關(guān)鍵字,便于用戶快速獲取新聞和郵件的主題。關(guān)鍵字可以為有意義的實體,比如,人名、電影,也可以為非實體的關(guān)鍵詞匯,如,上課、考研。

[[419347]]

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

引言

在實際應(yīng)用開發(fā)中,時不時的會遇到AI領(lǐng)域相關(guān)的一些技術(shù),本節(jié)旨在詳細(xì)講述關(guān)鍵字獲取技術(shù),關(guān)鍵字獲取涉及各個領(lǐng)域中,如:游記摘要、新聞標(biāo)簽、雜志文刊等。所以對于HarmonyOS開發(fā)者而言,了解和掌握HarmonyOS AI領(lǐng)域相關(guān)技術(shù)是至關(guān)重要的,也是每一個HarmonyOS開發(fā)者的一項必不可少的專業(yè)技能。

功能介紹

關(guān)鍵字提取主要用于從新聞和郵件里提取出關(guān)鍵字,便于用戶快速獲取新聞和郵件的主題。關(guān)鍵字可以為有意義的實體,比如,人名、電影,也可以為非實體的關(guān)鍵詞匯,如,上課、考研。

開發(fā)指南

1、使用NluClient靜態(tài)類進行初始化,通過異步方式獲取服務(wù)的連接

  1. NluClient.getInstance().init(context, new OnResultListener<Integer>(){ 
  2.       @Override 
  3.       public void onResult(Integer result){ 
  4.        // 初始化成功回調(diào),在服務(wù)初始化成功調(diào)用該函數(shù) 
  5.       } 
  6.   }, true); 

2、調(diào)用獲取關(guān)鍵詞提取方法得到分析結(jié)果,同一個接口提供了同步和異步兩個方法

同步:

  1. String requestData= "{number:2,body:'今天我們一起去上課吧',title:'一起去上課'}"
  2. ResponseResult respResult = NluClient.getInstance().getKeywords(requestData, NluRequestType.REQUEST_TYPE_LOCAL); 
  3. if (null != respResult){ 
  4.      // 獲取接口返回結(jié)果,參考接口文檔返回使用 
  5.      String result = respResult.getResponseResult(); 

異步:

  1. // 待分析文本 
  2. String requestData= "{number:2,body:'今天我們一起去上課吧',title:'一起去上課'}"
  3. // 調(diào)用接口 
  4. NluClient.getInstance().getKeywords(requestData, NluRequestType.REQUEST_TYPE_LOCAL,new OnResultListener<ResponseResult>(){ 
  5.     @Override 
  6.     public void onResult(ResponseResult respResult) 
  7.     { 
  8.     // 異步返回 
  9.     if(null != respResult && NluError.SUCCESS_RESULT == respResult.getCode()) 
  10.         { 
  11.         // 獲取接口返回結(jié)果,參考接口文檔返回使用 
  12.         String result = respResult.getResponseResult(); 
  13.         } 
  14.     } 
  15. }); 

3、使用結(jié)束調(diào)用destroy()方法釋放進程資源

  1. NluClient.getInstance().destroy(this); 

示例代碼

1、xml布局

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <DirectionalLayout 
  3.   xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  4.   ohos:height="match_parent" 
  5.   ohos:orientation="vertical" 
  6.   ohos:width="match_parent"
  7.   <Text 
  8.     ohos:background_element="$graphic:background_ability_main" 
  9.     ohos:height="match_content" 
  10.     ohos:layout_alignment="horizontal_center" 
  11.     ohos:multiple_lines="true" 
  12.     ohos:text="$string:title" 
  13.     ohos:top_margin="50vp" 
  14.     ohos:text_size="50" 
  15.     ohos:width="match_content" 
  16.     /> 
  17.   <Text 
  18.     ohos:background_element="$graphic:background_ability_main" 
  19.     ohos:height="match_content" 
  20.     ohos:layout_alignment="horizontal_center" 
  21.     ohos:multiple_lines="true" 
  22.     ohos:left_margin="10vp" 
  23.     ohos:right_margin="10vp" 
  24.     ohos:text="body:'同步-今天我們一起去上課吧',title:'同步-一起去上課'-body:'異步-今天我們一起去上班吧',title:'異步-我們?nèi)ド习?" 
  25.     ohos:top_margin="50vp" 
  26.     ohos:text_size="50" 
  27.     ohos:width="match_content" 
  28.     /> 
  29.   <Text 
  30.     ohos:background_element="$graphic:background_ability_main" 
  31.     ohos:height="match_content" 
  32.     ohos:id="$+id:text_content" 
  33.     ohos:layout_alignment="horizontal_center" 
  34.     ohos:multiple_lines="true" 
  35.     ohos:top_margin="50vp" 
  36.     ohos:left_margin="10vp" 
  37.     ohos:right_margin="10vp" 
  38.     ohos:text_size="50" 
  39.     ohos:width="match_content" 
  40.     /> 
  41.   <Text 
  42.     ohos:background_element="$graphic:background_ability_main" 
  43.     ohos:height="match_content" 
  44.     ohos:id="$+id:text_asynchronous" 
  45.     ohos:layout_alignment="horizontal_center" 
  46.     ohos:text="$string:asynchronous" 
  47.     ohos:top_margin="50vp" 
  48.     ohos:text_size="50" 
  49.     ohos:width="match_content" 
  50.     /> 
  51.   <Text 
  52.     ohos:background_element="$graphic:background_ability_main" 
  53.     ohos:height="match_content" 
  54.     ohos:id="$+id:text_synchronization" 
  55.     ohos:layout_alignment="horizontal_center" 
  56.     ohos:text="$string:synchronization" 
  57.     ohos:top_margin="50vp" 
  58.     ohos:text_size="50" 
  59.     ohos:width="match_content" 
  60.     /> 
  61. </DirectionalLayout> 

2、案例代碼

  1. package com.example.keywords.slice; 
  2.  
  3. import com.example.keywords.ResourceTable; 
  4. import ohos.aafwk.ability.AbilitySlice; 
  5. import ohos.aafwk.content.Intent; 
  6. import ohos.agp.components.Component; 
  7. import ohos.agp.components.Component.ClickedListener; 
  8. import ohos.agp.components.Text; 
  9. import ohos.ai.nlu.NluClient; 
  10. import ohos.ai.nlu.NluRequestType; 
  11. import ohos.ai.nlu.ResponseResult; 
  12. import ohos.ai.nlu.util.NluError; 
  13.  
  14. public class MainAbilitySlice extends AbilitySlice implements ClickedListener { 
  15.  
  16.   private Text text_content; 
  17.  
  18.   @Override 
  19.   public void onStart(Intent intent) { 
  20.     super.onStart(intent); 
  21.     super.setUIContent(ResourceTable.Layout_ability_main); 
  22.     text_content = (Text) findComponentById(ResourceTable.Id_text_content); 
  23.     Text text_synchronization = (Text) findComponentById(ResourceTable.Id_text_synchronization); 
  24.     Text text_asynchronous = (Text) findComponentById(ResourceTable.Id_text_asynchronous); 
  25.     text_synchronization.setClickedListener(this); 
  26.     text_asynchronous.setClickedListener(this); 
  27.     // 使用NluClient靜態(tài)類初始化,通過異步方式獲取服務(wù)連接 
  28.     NluClient.getInstance().init(this, nulltrue); 
  29.   } 
  30.  
  31.   @Override 
  32.   public void onClick(Component component) { 
  33.     switch (component.getId()) { 
  34.       case ResourceTable.Id_text_synchronization: 
  35.         String requestData = "{number:3,body:'同步-今天我們一起去上課吧',title:'同步-一起去上課'}"
  36.         ResponseResult responseResult = NluClient.getInstance() 
  37.             .getKeywords(requestData, NluRequestType.REQUEST_TYPE_LOCAL); 
  38.         if (responseResult != null) { 
  39.           text_content.setText(responseResult.getResponseResult()); 
  40.         } 
  41.         break; 
  42.       case ResourceTable.Id_text_asynchronous: 
  43.         String rData = "{number:3,body:'異步-今天我們一起去上班吧',title:'異步-我們?nèi)ド习?}"
  44.         NluClient.getInstance().getKeywords(rData, NluRequestType.REQUEST_TYPE_LOCAL, 
  45.                 responseResult1 -> { 
  46.                   if (responseResult1 != null && NluError.SUCCESS_RESULT == responseResult1.getCode()) { 
  47.                     getAbility().getUITaskDispatcher().syncDispatch(() -> text_content.setText(responseResult1.getResponseResult())); 
  48.                   } 
  49.                 }); 
  50.         break; 
  51.       default
  52.         break; 
  53.     } 
  54.   } 
  55.  
  56.   @Override 
  57.   protected void onBackground() { 
  58.     super.onBackground(); 
  59.     NluClient.getInstance().destroy(this); 
  60.   } 

實現(xiàn)效果

【軟通動力】HarmonyOS AI基礎(chǔ)技術(shù)賦能之關(guān)鍵字獲取-鴻蒙HarmonyOS技術(shù)社區(qū)
【軟通動力】HarmonyOS AI基礎(chǔ)技術(shù)賦能之關(guān)鍵字獲取-鴻蒙HarmonyOS技術(shù)社區(qū)

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-09-23 10:00:57

鴻蒙HarmonyOS應(yīng)用

2021-09-13 15:14:01

鴻蒙HarmonyOS應(yīng)用

2011-06-27 15:08:15

SEO

2019-12-20 15:19:41

Synchroinze線程安全

2011-06-21 09:50:51

volatile

2021-08-31 14:58:52

鴻蒙HarmonyOS應(yīng)用

2022-08-17 07:53:10

Volatile關(guān)鍵字原子性

2021-01-05 10:26:50

鴻蒙Javafinal

2009-12-18 11:37:54

Ruby關(guān)鍵字yiel

2021-09-03 15:27:17

鴻蒙HarmonyOS應(yīng)用

2021-04-18 07:58:22

SQL Server數(shù)據(jù)庫Apply

2009-11-26 19:24:54

PHP類CMS

2023-11-10 09:29:30

MySQLExplain

2021-08-15 08:11:54

AndroidSynchronize關(guān)鍵字

2024-03-15 11:52:03

C++關(guān)鍵字編程

2020-03-05 11:15:32

IBM混合云

2009-08-21 14:58:56

C# this關(guān)鍵字

2018-04-20 15:56:09

Pythonglobal關(guān)鍵字

2013-01-30 10:12:14

Pythonyield
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 久久综合99 | 午夜精品一区二区三区在线播放 | 久草欧美 | 亚洲一区在线日韩在线深爱 | 成人做爰www免费看视频网站 | 超碰美女在线 | 日韩欧美一级精品久久 | 激情福利视频 | 日韩中文在线观看 | 国产欧美精品一区二区 | 欧美成人精品一区二区男人看 | 一区二区三区国产在线观看 | 日本精品一区二区三区视频 | 精品自拍视频 | 一区日韩 | 欧美激情久久久 | 中文字幕电影在线观看 | 狠狠狠色丁香婷婷综合久久五月 | 精品色 | www国产亚洲精品久久网站 | 凹凸日日摸日日碰夜夜 | 成人免费在线电影 | 天天玩夜夜操 | 国产精品色婷婷久久58 | 亚洲精品乱码久久久久久9色 | 成人在线视频网址 | 欧美a v在线 | 亚洲v日韩v综合v精品v | 午夜视频免费在线观看 | 91在线视频观看免费 | 视频一区中文字幕 | 欧美激情精品久久久久 | 久久久蜜桃一区二区人 | 精品在线一区二区 | 国产成人免费在线 | 国产免费观看一级国产 | 欧美极品在线观看 | aaaa一级毛片 | 91在线观看 | 在线观看h视频 | 亚洲性视频|