Table of Contents

Method Parse

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

Parse(CancellationToken)

Parses the content synchronously to extract the defined elements.

public TextExtractionResult Parse(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

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

Returns

TextExtractionResult

A TextExtractionResult containing the extracted elements.

Examples

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

// 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 synchronously
TextExtractionResult result = textExtraction.Parse();

// 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.

Exception

Propagates any exceptions thrown during the asynchronous parsing operation.