日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
HarmonyOSAI基礎(chǔ)技術(shù)賦能之關(guān)鍵字獲取

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

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、重慶小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了喀喇沁免費建站歡迎大家使用!

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

https://harmonyos.

引言

在實際應用開發(fā)中,時不時的會遇到AI領(lǐng)域相關(guān)的一些技術(shù),本節(jié)旨在詳細講述關(guān)鍵字獲取技術(shù),關(guān)鍵字獲取涉及各個領(lǐng)域中,如:游記摘要、新聞標簽、雜志文刊等。所以對于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(){ 
  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(){ 
  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.  
  2.   xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  3.   ohos:height="match_parent" 
  4.   ohos:orientation="vertical" 
  5.   ohos:width="match_parent"> 
  6.   
  7.     ohos:background_element="$graphic:background_ability_main" 
  8.     ohos:height="match_content" 
  9.     ohos:layout_alignment="horizontal_center" 
  10.     ohos:multiple_lines="true" 
  11.     ohos:text="$string:title" 
  12.     ohos:top_margin="50vp" 
  13.     ohos:text_size="50" 
  14.     ohos:width="match_content" 
  15.     /> 
  16.   
  17.     ohos:background_element="$graphic:background_ability_main" 
  18.     ohos:height="match_content" 
  19.     ohos:layout_alignment="horizontal_center" 
  20.     ohos:multiple_lines="true" 
  21.     ohos:left_margin="10vp" 
  22.     ohos:right_margin="10vp" 
  23.     ohos:text="body:'同步-今天我們一起去上課吧',title:'同步-一起去上課'-body:'異步-今天我們一起去上班吧',title:'異步-我們?nèi)ド习?" 
  24.     ohos:top_margin="50vp" 
  25.     ohos:text_size="50" 
  26.     ohos:width="match_content" 
  27.     /> 
  28.   
  29.     ohos:background_element="$graphic:background_ability_main" 
  30.     ohos:height="match_content" 
  31.     ohos:id="$+id:text_content" 
  32.     ohos:layout_alignment="horizontal_center" 
  33.     ohos:multiple_lines="true" 
  34.     ohos:top_margin="50vp" 
  35.     ohos:left_margin="10vp" 
  36.     ohos:right_margin="10vp" 
  37.     ohos:text_size="50" 
  38.     ohos:width="match_content" 
  39.     /> 
  40.   
  41.     ohos:background_element="$graphic:background_ability_main" 
  42.     ohos:height="match_content" 
  43.     ohos:id="$+id:text_asynchronous" 
  44.     ohos:layout_alignment="horizontal_center" 
  45.     ohos:text="$string:asynchronous" 
  46.     ohos:top_margin="50vp" 
  47.     ohos:text_size="50" 
  48.     ohos:width="match_content" 
  49.     /> 
  50.   
  51.     ohos:background_element="$graphic:background_ability_main" 
  52.     ohos:height="match_content" 
  53.     ohos:id="$+id:text_synchronization" 
  54.     ohos:layout_alignment="horizontal_center" 
  55.     ohos:text="$string:synchronization" 
  56.     ohos:top_margin="50vp" 
  57.     ohos:text_size="50" 
  58.     ohos:width="match_content" 
  59.     /> 
  60.  

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, null, true); 
  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)效果

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

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

https://harmonyos.


分享名稱:HarmonyOSAI基礎(chǔ)技術(shù)賦能之關(guān)鍵字獲取
標題路徑:http://m.5511xx.com/article/dheceid.html