偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

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

[[419347]]

想了解更多內(nèi)容,請?jiān)L問:

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

https://harmonyos.51cto.com

引言

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

功能介紹

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

開發(fā)指南

1、使用NluClient靜態(tài)類進(jìn)行初始化,通過異步方式獲取服務(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é)果,同一個(gè)接口提供了同步和異步兩個(gè)方法

同步:

  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()方法釋放進(jìn)程資源

  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.   } 

實(shí)現(xiàn)效果

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

想了解更多內(nèi)容,請?jiān)L問:

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
點(diǎn)贊
收藏

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