Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragaeeb/kokokor/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Kokokor provides several option types to configure the text reconstruction pipeline, including line detection, paragraph grouping, poetry detection, and centering analysis.ReconstructOptions
Optional knobs for one-shot paragraph reconstruction via reconstructParagraphs.Type Definition
Fields
Line-detection options. See MapObservationsToTextLinesOptions for available fields.
Paragraph-detection options. See ParagraphOptions for available fields.
Text formatting options.
Optional symbol to insert before the first footnote in the formatted output.Example:
"---" or "***"Usage Example
MapObservationsToTextLinesOptions
Configuration options for the main text line mapping function. This type combines all the configuration needed to process OCR observations into structured text lines.Type Definition
Fields
Inherited from CenteringOptions. The tolerance for center point alignment as a ratio of image width.
Inherited from CenteringOptions. The minimum margin required on each side as a ratio of image width.
Optional array of horizontal line elements detected in the document.These are typically used to identify sections, headers, footers, or decorative elements. When provided, text appearing below these lines may be classified as footnotes.
Are the coordinates from a RTL language? If true, the x-axis will be flipped.
Optional fixed line height factor for grouping observations into lines.If not provided, the system will compute an adaptive factor based on document analysis.Typical values:
- 0.5: Very tight line grouping
- 1.0: Standard line height
- 1.5: Generous line spacing tolerance
Optional logging function for debugging and monitoring the text processing pipeline.When provided, the system will output detailed information about its decisions and intermediate processing steps.
Additional vertical tolerance in pixels (at 72 DPI) for line grouping.This value is automatically scaled based on the document’s actual DPI.
- Higher values make line grouping more permissive (more text on same line)
- Lower values make line grouping stricter (more separate lines)
Configuration options for poetry detection algorithms.If not provided, default poetry detection settings will be used. Set to null or undefined to disable poetry detection entirely.See PoetryDetectionOptions for available fields.
Delimiter used when merging a detected poetry pair (hemistichs) into a single line.Example:
" ... " formats a pair as صدر ... عجز.Optional array of rectangular elements detected in the document.These are typically used to identify text boxes, highlighted sections, or headers. When provided, text within these rectangles may be classified as headings.
Usage Example
ParagraphOptions
Options for grouping text lines into paragraphs.Type Definition
Fields
Factor for detecting paragraph breaks based on vertical spacing.Higher values make break detection stricter (require larger gaps between paragraphs).
Threshold for identifying short lines that indicate paragraph endings.Lower values mark fewer lines as “short” (stricter definition of short lines).
Usage Example
PoetryDetectionOptions
Configuration options to fine-tune the poetry detection algorithm.Type Definition
Detection Heuristics
Poetry detection uses multiple heuristics:- Paired hemistichs: Two short lines that appear to be halves of a verse
- Merged lines: Single lines with distinctive spacing/density characteristics
- Centering: Lines that are centered with appropriate margins
Fields
Inherited from CenteringOptions. Used for centering-based poetry detection.
Inherited from CenteringOptions. Used for centering-based poetry detection.
Maximum allowed vertical gap between observations to be considered a poetry pair.This controls how close two lines must be to be considered hemistichs (halves of a verse).The gap is measured as a ratio of the average height of the two observations:
- 2.0 means the gap can be up to 200% of the average line height
- 1.5 would require closer spacing (150% of average height)
- 3.0 would allow wider spacing (300% of average height)
For merged lines heuristic: The minimum width a line must have to be considered.This prevents very short lines (like page numbers) from being analyzed for poetry.Specified as a ratio of the image width:
- 0.6 means the line must span at least 60% of the page width
- 0.4 would include shorter lines (40% of page width)
- 0.8 would require longer lines (80% of page width)
- null disables width filtering
The minimum number of words a line must contain to be considered poetry.This helps filter out noise like page numbers, single-word labels, or artifacts.Higher values reduce false positives but may miss short poetic lines.
For paired lines heuristic: How similar in width two hemistichs must be.This determines whether two lines are balanced enough to be verse halves.The similarity check:
|width1 - width2| / average(width1, width2) < ratio- 0.4 means widths can differ by up to 40% of their average
- 0.2 would require more similar widths (20% difference)
- 0.6 would allow more variation (60% difference)
For paired lines heuristic: How similar in word count two hemistichs must be.This ensures that verse halves have balanced content length.The similarity check:
|count1 - count2| / max(count1, count2) < ratio- 0.5 means word counts can differ by up to 50% of the larger count
- 0.3 would require more similar counts (30% difference)
- 0.7 would allow more variation (70% difference)
For merged lines heuristic: Word density threshold for identifying poetry.Poetry typically has lower word density (more spacing) than prose.A line is considered poetic if its density (words per pixel) is less than this ratio multiplied by the average prose density of the document.
- 0.8 means poetic lines should have ≤80% of average prose density
- 0.9 would require density closer to prose (≤90%)
- 0.7 would require sparser text (≤70% of prose density)
Usage Example
CenteringOptions
Configuration options for determining if text content is centered on a page.Type Definition
Fields
The tolerance for center point alignment as a ratio of image width.This determines how precisely text must be centered to be considered “centered”.Examples:
- 0.05 means the observation’s center can be within 5% of the page width from the true center
- 0.02 would require more precise centering (within 2%)
- 0.1 would allow looser centering requirements (within 10%)
The minimum margin required on each side as a ratio of image width.This ensures that “centered” text has adequate whitespace around it.Examples:
- 0.1 means there must be at least 10% of the page width as whitespace on both left and right sides
- 0.2 would require larger margins (20% on each side)
- 0.05 would allow tighter margins (5% on each side)
Usage Example
See Also
- reconstructParagraphs - Main function using these options
- mapObservationsToTextLines - Line detection function
- mapTextLinesToParagraphs - Paragraph grouping function