Skip to Content
DocumentationGetting Started

Getting Started

This guide covers the basics of using GLOST.

Installation

npm install @glotblocks/glost

For language-specific features, install the corresponding language package:

# Thai support npm install @glotblocks/glost-th # Japanese support npm install @glotblocks/glost-ja # Korean support npm install @glotblocks/glost-ko

Basic Usage

Creating Words

import { createGLOSTWordNode, createSimpleWord } from '@glotblocks/glost'; // Full control with createGLOSTWordNode const word = createGLOSTWordNode({ value: "hello", transcription: { ipa: { text: "həˈloʊ" } }, metadata: { partOfSpeech: "interjection" }, lang: "en", script: "latin", extras: { translations: { th: "สวัสดี" } } }); // Simplified helper const simple = createSimpleWord({ text: "hello", transliteration: "həˈloʊ", system: "ipa", partOfSpeech: "interjection" });

Creating Thai Words

import { createThaiWord } from '@glotblocks/glost-th'; const thaiWord = createThaiWord({ text: "สวัสดี", rtgs: "sawatdi", partOfSpeech: "interjection", tone: 2, syllables: ["sa", "wat", "di"] }); // Minimal - just text (transcription can be added by extensions) const minimalWord = createThaiWord({ text: "สวัสดี" });

Creating Japanese Words

import { createJapaneseWord } from '@glotblocks/glost-ja'; const japaneseWord = createJapaneseWord({ text: "こんにちは", romaji: "konnichiwa", partOfSpeech: "interjection", furigana: "こんにちは" }); // Minimal - just text const minimalWord = createJapaneseWord({ text: "こんにちは" });

Building Documents

import { createSentenceFromWords, createParagraphFromSentences, createDocumentFromParagraphs, createSimpleDocument } from '@glotblocks/glost'; // Build a sentence from words const sentence = createSentenceFromWords( [word1, word2, word3], "th", // language "thai", // script "สวัสดีครับ" // original text ); // Build a paragraph from sentences const paragraph = createParagraphFromSentences([sentence1, sentence2]); // Build a document from paragraphs const document = createDocumentFromParagraphs( [paragraph], "th", "thai", { title: "Greetings" } ); // Or use the simplified helper for quick prototypes const quickDoc = createSimpleDocument( [word1, word2], "th", "thai", { sentenceText: "สวัสดีครับ" } );

Traversing Documents

import { getAllWords, getAllSentences, getWordText, getWordTranscription } from '@glotblocks/glost'; // Get all words in a document const words = getAllWords(document); // Access word data words.forEach(word => { console.log(getWordText(word)); // "สวัสดี" console.log(getWordTranscription(word, "rtgs")); // "sawatdi" }); // Get all sentences const sentences = getAllSentences(document);

Using the Processor API

The v0.5+ processor uses a fluent API:

import { glost, createSimpleDocument } from '@glotblocks/glost'; import { createThaiWord } from '@glotblocks/glost-th'; // Create a document const words = [ createThaiWord({ text: "สวัสดี", rtgs: "sawatdi" }), createThaiWord({ text: "ครับ", rtgs: "khrap" }) ]; const document = createSimpleDocument(words, "th", "thai"); // Process with plugins const result = await glost() .use(myPlugin) .use(anotherPlugin) .process(document); // Access the processed document const processedDoc = result.document;

Using Presets

import { glost } from '@glotblocks/glost'; import { languageLearningPreset } from '@glotblocks/glost/presets'; const processor = glost() .use(languageLearningPreset) .freeze(); // Freeze for reuse // Process multiple documents const result1 = await processor.process(doc1); const result2 = await processor.process(doc2);

Language Code Flexibility

GLOST accepts multiple language code formats:

import { getLanguageName, toISO639_3 } from '@glotblocks/glost-common'; getLanguageName("th"); // "Thai" getLanguageName("tha"); // "Thai" toISO639_3("en"); // "eng"

See API Reference for complete language code and proficiency level functions.

Type Safety

GLOST provides type guards for safe node handling:

import { isGLOSTWord, isGLOSTSentence } from '@glotblocks/glost'; if (isGLOSTWord(node)) { // TypeScript knows node is GLOSTWord console.log(node.transcription); }
Last updated on