Skip to main content

Type definition

type Segment = {
  id: string;
  text: string;
};

Properties

id
string
required
Unique identifier for the segment. Typically follows patterns like P1234, B567a, H890 depending on the source corpus.
text
string
required
The Arabic text content of the segment. Can include Arabic script, diacritics, and punctuation.

Usage

The Segment type is the fundamental input unit for wobble-bibble. It represents a single piece of Arabic text that needs translation.

Creating segments

import type { Segment } from 'wobble-bibble';

const segments: Segment[] = [
  {
    id: 'P1234',
    text: 'قال رسول الله صلى الله عليه وسلم: إنما الأعمال بالنيات'
  },
  {
    id: 'P1235',
    text: 'وإنما لكل امرئ ما نوى'
  }
];

With validation

import { validateTranslationResponse, type Segment } from 'wobble-bibble';

const segments: Segment[] = [
  { id: 'P1', text: 'نص عربي...' },
  { id: 'P2', text: 'نص آخر...' }
];

const llmResponse = `P1 - Arabic text...
P2 - Another text...`;

const result = validateTranslationResponse(segments, llmResponse);

With prompt formatting

import { formatExcerptsForPrompt, getPrompt, type Segment } from 'wobble-bibble';

const segments: Segment[] = [
  { id: 'H123', text: 'حدثنا محمد بن يوسف...' }
];

const hadithPrompt = getPrompt('hadith');
const formatted = formatExcerptsForPrompt(segments, hadithPrompt.content);

Segment ID patterns

Common ID prefixes used in Islamic texts:
PrefixSource TypeExample
PGeneral paragraphP1234
HHadithH567
BBook sectionB890a
VVerse referenceV2:255
FFatwaF123
Segment IDs must remain consistent between input and output. The validator checks for invented IDs, duplicates, and missing gaps.

Build docs developers (and LLMs) love