Table of Contents

Method SetElementsFromJsonSchema

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

SetElementsFromJsonSchema(string)

Configures the text extraction elements by parsing a JSON schema.

public void SetElementsFromJsonSchema(string jsonSchema)

Parameters

jsonSchema string

A string containing the JSON schema that defines the structure, types, and optional descriptions of the extraction elements. The JSON schema can define simple elements, arrays, or complex objects with nested properties.

Examples

// Configure extraction elements based on the invoice JSON schema.
textExtraction.SetElementsFromJsonSchema(jsonSchema);

Remarks

This method uses ParseJsonSchema(string) to convert the JSON schema into a list of TextExtractionElement instances, which is then assigned to the Elements property. The JSON schema should follow the expected format, supporting keys such as "type", "description", "isArray", and "properties". For a sample invoice extraction, you can use the following JSON schema:

string jsonSchema = @"
{
  ""$schema"": ""http://json-schema.org/draft-07/schema#"",
  ""title"": ""Invoice Content Extraction"",
  ""type"": ""object"",
  ""properties"": {
    ""InvoiceNumber"": {
      ""type"": ""string"",
      ""description"": ""Unique identifier of the invoice""
    },
    ""InvoiceDate"": {
      ""type"": ""string"",
      ""format"": ""date"",
      ""description"": ""Date when the invoice was issued""
    },
    ""Currency"": {
      ""type"": ""string"",
      ""description"": ""Currency code in ISO format (e.g., USD, EUR)""
    },
    ""Vendor"": {
      ""type"": ""object"",
      ""description"": ""Details about the vendor issuing the invoice"",
      ""properties"": {
        ""Name"": {
          ""type"": ""string"",
          ""description"": ""The vendor's name""
        },
        ""Address"": {
          ""type"": ""object"",
          ""description"": ""Vendor address details"",
          ""properties"": {
            ""Street"": { ""type"": ""string"", ""description"": ""Street address"" },
            ""City"": { ""type"": ""string"", ""description"": ""City name"" },
            ""State"": { ""type"": ""string"", ""description"": ""State or region"" },
            ""ZipCode"": { ""type"": ""string"", ""description"": ""Postal or zip code"" },
            ""Country"": { ""type"": ""string"", ""description"": ""Country name"" }
          }
        },
        ""Contact"": {
          ""type"": ""string"",
          ""description"": ""Vendor contact information (phone, email, etc.)""
        }
      }
    },
    ""Customer"": {
      ""type"": ""object"",
      ""description"": ""Details about the customer receiving the invoice"",
      ""properties"": {
        ""Name"": {
          ""type"": ""string"",
          ""description"": ""The customer's name""
        },
        ""Address"": {
          ""type"": ""object"",
          ""description"": ""Customer address details"",
          ""properties"": {
            ""Street"": { ""type"": ""string"", ""description"": ""Street address"" },
            ""City"": { ""type"": ""string"", ""description"": ""City name"" },
            ""State"": { ""type"": ""string"", ""description"": ""State or region"" },
            ""ZipCode"": { ""type"": ""string"", ""description"": ""Postal or zip code"" },
            ""Country"": { ""type"": ""string"", ""description"": ""Country name"" }
          }
        },
        ""Contact"": {
          ""type"": ""string"",
          ""description"": ""Customer contact information (phone, email, etc.)""
        }
      }
    },
    ""Items"": {
      ""type"": ""array"",
      ""description"": ""List of invoice items"",
      ""items"": {
        ""type"": ""object"",
        ""properties"": {
          ""Description"": {
            ""type"": ""string"",
            ""description"": ""A description of the item or service""
          },
          ""Quantity"": {
            ""type"": ""number"",
            ""description"": ""The quantity of the item""
          },
          ""UnitPrice"": {
            ""type"": ""number"",
            ""description"": ""The unit price of the item""
          },
          ""LineTotal"": {
            ""type"": ""number"",
            ""description"": ""Total price for the line item (Quantity x UnitPrice)""
          }
        }
      }
    },
    ""Subtotal"": {
      ""type"": ""number"",
      ""description"": ""The subtotal amount for all items before tax and discounts""
    },
    ""Tax"": {
      ""type"": ""number"",
      ""description"": ""The total tax amount applied to the invoice""
    },
    ""Total"": {
      ""type"": ""number"",
      ""description"": ""The final total amount due""
    }
  }
}";