{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.lm-kit.com/lm-kit-net/schemas/parsed-document/v1.json",
  "title": "LM-Kit parsed document",
  "description": "A document parsed by LM-Kit.NET's DocumentParser, as ParsedDocument.ToJson() writes it and ParsedDocument.FromJson() reads it. Positions are in the page's unit, origin at the top-left corner. Readers of any 1.x version ignore members they do not know.",
  "type": "object",
  "required": ["schema_version", "pages"],
  "properties": {
    "$schema": { "type": "string", "description": "The identifier of this schema." },
    "schema_version": { "type": "string", "pattern": "^1(\\.[0-9]+)?$", "description": "The schema version the document follows, MAJOR.MINOR." },
    "source_name": { "type": "string", "description": "The source document's name; empty when it has none." },
    "elapsed_seconds": { "type": "number", "minimum": 0, "description": "The wall time the parse took." },
    "pages": { "type": "array", "items": { "$ref": "#/$defs/page" }, "description": "The parsed pages, in document order." }
  },
  "$defs": {
    "page": {
      "type": "object",
      "required": ["page_index", "width", "height", "unit", "elements"],
      "properties": {
        "page_index": { "type": "integer", "minimum": 0, "description": "Zero-based page index in the source document." },
        "page_number": { "type": "integer", "minimum": 1, "description": "One-based page number." },
        "width": { "type": "number", "minimum": 0, "description": "Page width, in unit." },
        "height": { "type": "number", "minimum": 0, "description": "Page height, in unit." },
        "unit": {
          "type": "string",
          "enum": ["pixels", "device_independent_pixels", "points", "inches", "millimeters", "centimeters"],
          "description": "Unit of the page size and of every position: points for a document page, pixels for an image."
        },
        "elements": { "type": "array", "items": { "$ref": "#/$defs/element" }, "description": "Every element of the page, in reading order." },
        "blocks": { "type": "array", "items": { "$ref": "#/$defs/block" }, "description": "Layout blocks grouping elements of the page." },
        "figure_texts": { "type": "array", "items": { "$ref": "#/$defs/figure_text" }, "description": "Text runs figures print, each a child of its figure." },
        "regions": { "type": "array", "items": { "$ref": "#/$defs/region" }, "description": "Grounding regions: the partition of the page's elements into the units a reader points at, each with the box it occupies, followed by the grounding units that enclose or split them (a list, a run of lines, a row), which list no member and carry their own text. Absent when the page formed none; every element is then a region of its own." }
      }
    },
    "element": {
      "type": "object",
      "required": ["category", "reading_index", "content"],
      "properties": {
        "category": {
          "type": "string",
          "description": "The element's semantic role. Readers map a category they do not know to unknown.",
          "examples": ["unknown", "text", "title", "header", "footer", "figure", "figure_caption", "figure_footnote", "table", "table_caption", "table_footnote", "formula", "formula_caption", "page_footnote"]
        },
        "reading_index": { "type": "integer", "minimum": 0, "description": "Zero-based position in the page's reading order." },
        "confidence": { "type": ["number", "null"], "minimum": 0, "maximum": 1, "description": "Confidence in the region and its role; 1 when none is estimated." },
        "bbox": { "$ref": "#/$defs/bbox" },
        "polygon": { "$ref": "#/$defs/polygon" },
        "content": { "$ref": "#/$defs/content" },
        "image": { "$ref": "#/$defs/image" },
        "printed_words": { "type": "array", "items": { "type": "string" }, "description": "The words printed inside a figure's box, in print order." },
        "recognized_words": { "type": "array", "items": { "type": "string" }, "description": "The words an OCR engine read off the element's pixels where the text layer prints none, in print order; a picture that prints them as text renders them." }
      }
    },
    "content": {
      "type": "object",
      "required": ["type", "text"],
      "properties": {
        "type": {
          "type": "string",
          "description": "The content type. Readers read a type they do not know as text.",
          "examples": ["text", "table", "formula", "chart", "figure", "figure_caption", "figure_label", "repeated_text"]
        },
        "format": { "type": "string", "enum": ["markdown", "html", "latex", "text"], "description": "How text is encoded." },
        "text": { "type": "string", "description": "The content: Markdown for text, HTML for a table (header rows resolved), LaTeX for a formula, a Markdown table for a chart, a description for a figure." },
        "caption": { "type": "string", "description": "Chart: the title the figure prints for itself." },
        "piece_title": { "type": "string", "description": "Chart: the title printed inside the plot's box." },
        "legend": { "type": "string", "description": "Chart: the legend words the table does not carry." },
        "panels": {
          "type": "array",
          "description": "Chart: one table per panel of a multi-panel figure.",
          "items": {
            "type": "object",
            "required": ["text"],
            "properties": {
              "title": { "type": "string", "description": "The words printed over the panel." },
              "text": { "type": "string", "description": "The panel's data as a Markdown table." }
            }
          }
        },
        "table_caption": { "type": "string", "description": "Chart: the caption the chart's tables carry inside themselves when rendered as HTML." },
        "group_rows_as_headers": { "type": "boolean", "description": "Chart: whether a row naming a group of rows renders as a header spanning every column." }
      }
    },
    "image": {
      "type": "object",
      "required": ["mime_type", "data"],
      "description": "The picture of a figure or chart, present when the parser kept figure images.",
      "properties": {
        "mime_type": { "type": "string", "description": "The encoding of data, for example image/png." },
        "width": { "type": "integer", "minimum": 0, "description": "Width in pixels." },
        "height": { "type": "integer", "minimum": 0, "description": "Height in pixels." },
        "data": { "type": "string", "contentEncoding": "base64", "description": "The encoded picture." }
      }
    },
    "block": {
      "type": "object",
      "required": ["kind", "members"],
      "properties": {
        "kind": { "type": "string", "enum": ["column", "row", "figure"], "description": "How the members are set: one under another, side by side on one row, or a chart with what the page prints for it outside its drawing." },
        "likelihood": { "type": ["number", "null"], "minimum": 0, "maximum": 1, "description": "The probability that the members form one group; null when none is estimated." },
        "bbox": { "$ref": "#/$defs/bbox" },
        "polygon": { "$ref": "#/$defs/polygon" },
        "members": { "type": "array", "items": { "type": "integer", "minimum": 0 }, "description": "Positions of the members in the page's elements array." },
        "text": { "type": "string", "description": "The members' text in reading order." }
      }
    },
    "region": {
      "type": "object",
      "required": ["category", "members"],
      "properties": {
        "category": { "type": "string", "description": "The region's role: its element's category for a region of one element; title when every member is a title, text otherwise." },
        "bbox": { "$ref": "#/$defs/bbox" },
        "polygon": { "$ref": "#/$defs/polygon" },
        "members": { "type": "array", "items": { "type": "integer", "minimum": 0 }, "description": "Positions of the members in the page's elements array, in reading order; empty for a grounding unit, which is no element of the page." },
        "text": { "type": "string", "description": "The members' text in reading order; written for a region of several elements and for a grounding unit (the words it covers), never for a region of one element, which prints that element's text." },
        "confidence": { "type": ["number", "null"], "minimum": 0, "maximum": 1, "description": "A grounding unit's confidence in the region and its role; written for grounding units only." }
      }
    },
    "figure_text": {
      "type": "object",
      "required": ["text"],
      "properties": {
        "figure": { "type": "integer", "minimum": 0, "description": "Position of the figure that prints the text in the page's elements array." },
        "bbox": { "$ref": "#/$defs/bbox" },
        "polygon": { "$ref": "#/$defs/polygon" },
        "text": { "type": "string", "description": "The printed lines, one per line." }
      }
    },
    "bbox": {
      "type": "array",
      "items": { "type": "number" },
      "minItems": 4,
      "maxItems": 4,
      "description": "The box as left, top, right, bottom."
    },
    "polygon": {
      "type": "array",
      "items": { "type": "number" },
      "minItems": 8,
      "maxItems": 8,
      "description": "The four corners clockwise from the top-left, x then y."
    }
  }
}
