public class NluClient extends Object
For example, you use these methods to initialize the NLU engine service, recognize entities, attach part of speech (POS) tags, and recognize intentions.
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
destroy(Context context) |
Destroys the NLU service by canceling all ongoing NLU tasks.
|
ResponseResult |
getAssistantIntention(String requestData,
int requestType) |
Recognizes assistant intentions and obtains the recognition result (synchronous method).
|
ResponseResult |
getAssistantIntention(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Recognizes assistant intentions and obtains the recognition result (asynchronous method).
|
ResponseResult |
getChatIntention(String requestData,
int requestType) |
Recognizes Information Message (IM) intentions and obtains the recognition result (synchronous method).
|
ResponseResult |
getChatIntention(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Recognizes IM intentions and obtains the recognition result (asynchronous method).
|
ResponseResult |
getEntity(String requestData,
int requestType) |
Recognizes entities and obtains the recognition result (synchronous method).
|
ResponseResult |
getEntity(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Recognizes entities and obtains the recognition result (asynchronous method).
|
static NluClient |
getInstance() |
Returns a singleton instance of
NluClient. |
ResponseResult |
getKeywords(String requestData,
int requestType) |
Extracts and obtains keywords (synchronous method).
|
ResponseResult |
getKeywords(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Extracts and obtains keywords (asynchronous method).
|
ResponseResult |
getWordPos(String requestData,
int requestType) |
Attaches POS tags to words and obtains the POS tags (synchronous method).
|
ResponseResult |
getWordPos(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Attaches POS tags to words and obtains the POS tags (asynchronous method).
|
ResponseResult |
getWordSegment(String requestData,
int requestType) |
Segments Chinese text and obtains the segmentation result (synchronous method).
|
ResponseResult |
getWordSegment(String requestData,
int requestType,
OnResultListener<ResponseResult> listener) |
Segments Chinese text and obtains the segmentation result (asynchronous method).
|
void |
init(Context context,
OnResultListener<Integer> listener,
boolean isLoadModel) |
Initializes the NLU engine service.
|
public static NluClient getInstance()
NluClient.
If there is an NluClient object, this method will return it to the caller.
If there is no NluClient object, this method will create one and return it to the caller.
NluClient.public void init(Context context, OnResultListener<Integer> listener, boolean isLoadModel)
An NLU listener is passed to this method for observing the process and result of an NLU method call,
and initialization parameters are passed for initializing the NLU engine. You must use this method
and obtain the result of OnResultListener#onResult(Object)} before calling NLU-specific methods.
context - Indicates the context to use. This parameter cannot be null.listener - Indicates the listener to observe the process and result of NLU method calls.isLoadModel - Specifies whether an NLU model needs to be loaded.public ResponseResult getWordSegment(String requestData, int requestType)
You can use this method to segment a piece of Chinese text into single words at a specific granularity.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
0 (default value): The text is divided into basic words, without combining any entities.1: The text is divided into basic words and certain entities are combined.9223372036854775807 (2 to the power of 63 minus 1): The text is divided into basic words and
certain entities are combined. In addition, the overall structures such as time and location are combined
except that they are separated by symbols, and some common phrases are also combined.requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getWordSegment(String requestData, int requestType, OnResultListener<ResponseResult> listener)
You can use this method to segment a piece of Chinese text into single words at a specific granularity.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
0 (default value): The text is divided into basic words, without combining any entities.1: The text is divided into basic words and certain entities are combined.9223372036854775807 (2 to the power of 63 minus 1): The text is divided into basic words and
certain entities are combined. In addition, the overall structures such as time and location are combined
except that they are separated by symbols, and some common phrases are also combined.requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message,
and response result (both result code and message) represented by responseResult.public ResponseResult getEntity(String requestData, int requestType)
You can use this method to recognize entities with particular meanings in the text, including movies, TV series, variety shows, animations, songs, albums, books, train numbers, flight numbers, teams, names, express delivery numbers, phone numbers, URLs, email addresses, leagues, time, locations (for example, locations of hotels, restaurants, scenic spots, schools, and roads), and verification codes.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
It includes the mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 500.requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message,
and response result (both result code and message) represented by responseResult.public ResponseResult getEntity(String requestData, int requestType, OnResultListener<ResponseResult> listener)
You can use this method to recognize entities with particular meanings in the text, including movies, TV series, variety shows, animations, songs, albums, books, train numbers, flight numbers, teams, names, express delivery numbers, phone numbers, URLs, email addresses, leagues, time, locations (for example, locations of hotels, restaurants, scenic spots, schools, and roads), and verification codes.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
It includes the mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 500.requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message,
and response result (both result code and message) represented by responseResult.public ResponseResult getWordPos(String requestData, int requestType)
After determining the granularity of word segmentation, you can use this method to attach a deserved POS tag to each segmented word. The POS tag specifies whether a word is a noun, verb, adjective, or of any other POS.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
0 (default value): The text is divided into basic words, without combining any entities.1: The text is divided into basic words and certain entities are combined.9223372036854775807 (2 to the power of 63 minus 1): The text is divided into basic words and
certain entities are combined. In addition, the overall structures such as time and location are combined
except that they are separated by symbols, and some common phrases are also combined.requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getWordPos(String requestData, int requestType, OnResultListener<ResponseResult> listener)
After determining the granularity of word segmentation, you can use this method to attach a deserved POS tag to each segmented word. The POS tag specifies whether a word is a noun, verb, adjective, or of any other POS.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
0 (default value): The text is divided into basic words, without combining any entities.1: The text is divided into basic words and certain entities are combined.9223372036854775807 (2 to the power of 63 minus 1): The text is divided into basic words and
certain entities are combined. In addition, the overall structures such as time and location are combined
except that they are separated by symbols, and some common phrases are also combined.requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getChatIntention(String requestData, int requestType)
Currently, the following intentions are supported: repayment notification, repayment success notification, and missed call notification.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
It includes the mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 500.requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getChatIntention(String requestData, int requestType, OnResultListener<ResponseResult> listener)
Currently, the following intentions are supported: repayment notification, repayment success notification, and missed call notification.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
It includes the mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 500.requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message,
and response result (both result code and message) represented by responseResult.public ResponseResult getAssistantIntention(String requestData, int requestType)
You can use this method to recognize and analyze assistant intentions specific to system settings, trip, life, recreation, contacts, application control, and system applications.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
It includes the mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 50.requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getAssistantIntention(String requestData, int requestType, OnResultListener<ResponseResult> listener)
You can use this method to recognize and analyze assistant intentions specific to system settings, trip, life, recreation, contacts, application control, and system applications.
requestData - Indicates the text in the JSON format. This parameter cannot be null. It includes the
mandatory field text, which indicates the UTF-8-encoded text to be segmented.
The maximum length is 50.requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message,
and response result (both result code and message) represented by responseResult.public ResponseResult getKeywords(String requestData, int requestType)
You can use this method to extract keywords from news and emails.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
requestType - Indicates the request type, which is defined in NluRequestType.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public ResponseResult getKeywords(String requestData, int requestType, OnResultListener<ResponseResult> listener)
You can use this method to extract keywords from news and emails.
requestData - Indicates the text in the JSON format. This parameter cannot be null.
requestType - Indicates the request type, which is defined in NluRequestType.listener - Indicates the listener to observe the process and result of NLU method calls.ResponseResult object, which contains the result
code represented by Code, result message represented by Message, and response
result (both result code and message) represented by responseResult.public void destroy(Context context)
The destroyed NLU service can no longer be used. To use the NLU service again, you need to
call init(ohos.app.Context,ohos.ai.nlu.OnResultListener,boolean) to create another NluClient instance.
context - Indicates the context to use. This parameter cannot be null.