Table of Contents

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 string

The plain text that needs to be classified.

normalize bool

Optional. Indicates whether input parameters should be normalized. The default value is true.

cancellationToken CancellationToken

Optional. 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 the candidate text. Returns -1 if no category can be associated.

Exceptions

OperationCanceledException

Thrown if the operation is cancelled via the cancellationToken.