Table of Contents

Method ParseAsync

Namespace
LMKit.Extraction
Assembly
LM-Kit.NET.dll

ParseAsync(CancellationToken)

Parses the content asynchronously to extract the defined elements.

public Task<TextExtractionResult> ParseAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests. The default value is None.

Returns

Task<TextExtractionResult>

A task that represents the asynchronous operation. The task result contains a TextExtractionResult with the extracted elements.

Examples

using LMKit.Extraction;
using LMKit.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

// Initialize the language model (LLM)
LLM languageModel = new LLM("path/to/your/model");

// Create an instance of TextExtraction using the LLM
TextExtraction textExtraction = new TextExtraction(languageModel);

// Define the elements to extract
textExtraction.Elements = new List<TextExtractionElement>
{
    new TextExtractionElement("Name", ElementType.String, "The person's full name"),
    new TextExtractionElement("Age", ElementType.Integer, "The person's age"),
    new TextExtractionElement("Birth Date", ElementType.Date, "The person's date of birth.")
};

// Set the content to extract data from
textExtraction.SetContent("Jane Smith, aged 28, born on 5 Nov of the year 1981");

// Perform the extraction asynchronously
TextExtractionResult result = await textExtraction.ParseAsync();

// Access the extracted items
foreach (var item in result.Items)
{
    Console.WriteLine($"{item.TextExtractionElement.Name}: {item.Value}");
}

Exceptions

InvalidOperationException

Thrown if no elements are defined or if no content has been set.