Method GetBestCategoryAsync
- Namespace
- LMKit.TextAnalysis
- Assembly
- LM-Kit.NET.dll
GetBestCategoryAsync(IList<string>, string, bool, CancellationToken)
Classifies a given text into one of the categories from a predefined list asynchronously.
public Task<int> GetBestCategoryAsync(IList<string> categories, string candidate, bool normalize = true, CancellationToken cancellationToken = default)
Parameters
categories
IList<string>A list of predefined categories. Each entry should provide a description of its corresponding category.
candidate
stringThe plain text that needs to be classified.
normalize
boolOptional. Indicates whether input parameters should be normalized. The default value is true.
cancellationToken
CancellationTokenOptional. A CancellationToken to handle cancellation requests.
Returns
- Task<int>
A task representing the asynchronous operation. The task result contains the index within the
categories
list that best matches the category associated with thecandidate
text. Returns -1 if no category can be associated.
Exceptions
- OperationCanceledException
Thrown if the operation is cancelled via the
cancellationToken
.