Location>code7788 >text

Integrate natural language understanding services to make apps "understand people"

Popularity:196 ℃/2024-12-18 00:33:16

Nowadays, application intelligence has become a trend, developers want to realize intelligence, then first need to give the application the ability to understand natural language, so that it can accurately understand the human language, and then respond to the user's needs, and provide a series of intelligent services. For example, the user's voice control application to help book tickets, the application will be converted to text, the application needs to accurately understand the content of the instructions through technical processing, before you can pull the corresponding program functions to provide services.

HarmonyOS SDKnatural language understanding service(The Natural Language Kit (NLK) provides a number of basic capabilities related to semantic understanding of text, which currently includeparticiplerespond in singingphysical extractionthat can help developers better process and analyze text data.

participle

Segmentation can slice a text into independent word units and identify each word in a sentence, including Chinese, English and numeric content, thus laying the foundation for subsequent tasks such as semantic analysis and information extraction.

In the actual application of the scene, the search engine will use this function, when the user enters the text content to be searched, the search engine will first be word processing, in the extraction of keywords and then match the search.

development step

The development of participle processing is divided into 3 steps.

1. Reference to the relevant class added to the project.

import { textProcessing } from '@';

2. Configure the input text box and button to call the splitter interface.

let inputText: string = '';

TextInput({ placeholder: 'Please enter text' })
  .height(40)
  .fontSize(16)
  .width('90%')
  .margin(10)
  .onChange((value: string) => {
     = value;
  })

Button('Getting Segmentation Results')
  .type()
  .fontColor()
  .width('45%')
  .margin(10)
  .onClick(async () => {
    try {
      let result = await ();
       = (result);
    } catch (err) {
      (`getWordSegment error: ${}`);
    }
  })

3. Show the result of word splitting on the interface.

private formatWordSegmentResult(segments: []): string {
  let output = 'Word Segments:\n';
  ((segment, index) => {
    output += `Word[${index}]: ${}, Tag: ${}\n`;
  });
  return output;
}

physical extraction

Entity extraction is a key capability for natural language processing, which can accurately recognize entities with specific meanings from text, such as names of people, places, time and date, numbers, phone numbers, email addresses and so on. Through entity extraction, developers can combine their business scenarios to develop a variety of intelligent applications and improve the user service experience.

For example, in news reading scenarios, developers can use the ability to extract entities from the body of the news, and highlight key entity information such as people's names, places, times, URLs, etc., so as to help readers quickly access the main points of the article, effectively improving the efficiency of information acquisition; in the scenario of users filling out the shipping address, developers can use the entity extraction ability to quickly identify the extraction of the recipient's name, address, cell phone number, etc., to provide structured text information for users to fill out the form quickly.

development step

The development of the entity extraction was divided into 4 steps.

1. Reference to the relevant class added to the project.

import { textProcessing, EntityType } from '@';

2. Configure the input text box.

let inputText: string = '';

TextInput({ placeholder: 'Please enter text' })
  .height(40)
  .fontSize(16)
  .width('90%')
  .margin(10)
  .onChange((value: string) => {
     = value;
  })

3. Configure the button to call the entity extraction interface.

Button('Get entity results')
  .type()
  .fontColor()
  .width('45%')
  .margin(10)
  .onClick(async () => {
    try {
      let result = await (, {entityTypes: [, EntityType.PHONE_NO]});
       = (result);
    } catch (err) {
      (`getEntity error: ${}`);
       = 'Error occurred while getting entities.';
    }
  })

4. Presentation of entity extraction results on the interface.

private formatEntityResult(entities: []): string {
  if (!entities || !) {
    return 'No entities found.';
  }

  let output = 'Entities:\n';
 for (let i = 0; i < ; i++) {
    let entity = entities[i];
    output += `Entity[${i}]:\n`;
    output += `  oriText: ${}\n`;
    output += `  charOffset: ${}\n`;
    output += `  entityType: ${}\n`;
    output += `  jsonObject: ${}\n\n`;
  }
  return output;

Natural language understanding services, as the basic capability that constitutes the development of intelligent applications, can be widely used in a variety of scenarios, such as news reading, information retrieval, customer service, social chatting, financial operations, and so on. With the continuous progress of technology, we expect developers to continue to explore and innovate, in order to explore more possibilities of intelligent applications, and to promote a higher level of intelligent development in the industry.

Find out more>>

interviewsNatural Language Understanding Service Consortium Official Website

gainNatural Language Understanding Service Development Guidance Document