Skip to main content

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.

Function Signature

mergeObservations<T extends Observation>(group: T[], delimiter?: string): T

Parameters

group
T[]
required
The group of observations to merge (T extends Observation)
delimiter
string
default:" "
Text delimiter used when concatenating observations (default: ’ ‘)

Returns

A single observation with:
  • Text concatenated with the specified delimiter
  • Bounding box adjusted to encompass all observations
  • All other properties preserved from the first observation

Description

Merges a group of observations into a single observation. This function performs the following operations:
  1. Calculates a combined bounding box that encompasses all observations in the group
  2. Concatenates the text content of all observations with the specified delimiter between them
  3. Preserves all additional properties from the first observation in the group
Typically used to combine individual word-level OCR results into complete lines or to merge line segments into full paragraphs.

Usage Example

import { mergeObservations } from 'kokokor';

const observations = [
  { text: 'Hello', bbox: { x: 100, y: 100, width: 50, height: 20 } },
  { text: 'world', bbox: { x: 160, y: 100, width: 50, height: 20 } },
  { text: '!', bbox: { x: 220, y: 100, width: 10, height: 20 } },
];

// Merge with default space delimiter
const merged = mergeObservations(observations);
console.log(merged.text); // "Hello world !"
console.log(merged.bbox); // { x: 100, y: 100, width: 130, height: 20 }

// Merge with custom delimiter
const merged2 = mergeObservations(observations, '-');
console.log(merged2.text); // "Hello-world-!"

// Merge poetry hemistichs with special delimiter
const hemistichs = [
  { text: 'First hemistich', bbox: { x: 200, y: 100, width: 150, height: 20 } },
  { text: 'Second hemistich', bbox: { x: 500, y: 100, width: 150, height: 20 } },
];

const poem = mergeObservations(hemistichs, ' ... ');
console.log(poem.text); // "First hemistich ... Second hemistich"