@tty-pt/lemma logo

@tty-pt/lemma

npm version License: BSD-2-Clause TypeScript Ready Node.js Native WebAssembly Zero Dependencies

Universal Node.js and Browser bindings for liblemma, the pure-C lexical tokenization, Unicode case-folding, lossless subword encoding, and full-text search engine. Represents the canonical Text Axis in the Corm Recall Kernel. Canonical C header: <ttypt/lemma.h>.

📖 Full C & Lexical Engine Documentation: See the main liblemma GitHub README for accent-preserving Unicode folding (lemma_fold), BPE subword tokenization (lemma_tok_encode), and C inverted index APIs.


1. Quickstart & Installation

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/lemma

Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (liblemma) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), and OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ — liblemma.xcframework) are available via the tty.pt package repositories.

import { foldAccents, tokenize, encodeTokens, decodeTokens, LemmaIndex } from "@tty-pt/lemma";

// 1. Unicode Case Folding (lowercasing while preserving language-specific accents)
const folded = foldAccents("Pão de Évora");
console.log(folded); // "pão de évora"

// 2. Tokenization into normalized word units & lossless subword encoding
const tokens = tokenize("O pão fresco na padaria!");
console.log(tokens); // ["pão", "fresco", "na", "padaria"]

const subwords = encodeTokens("Pão de queijo");
console.log(decodeTokens(subwords)); // "Pão de queijo"

// 3. Fast In-Memory Lexical Indexing & Search
const index = new LemmaIndex();
index.addDocument(1, "Padaria tradicional com pão fresco");
index.addDocument(2, "Restaurante de peixe grelhado");
index.addDocument(3, "Café com pão de queijo");

const results = index.search("pão");
console.log(results); // [{ id: 1, score: 1 }, { id: 3, score: 1 }]

2. Invariants & Multilingual Features


3. JavaScript / TypeScript API Reference

foldAccents(text: string): string

Applies Unicode-compliant case folding and diacritic normalization according to language rules. Executes strictly in compiled WebAssembly / C via lemma_fold(), with zero regex heuristic stripping.

tokenize(text: string): string[]

Tokenizes a string into normalized word tokens by folding accents and splitting on non-alphanumeric word boundaries.

encodeTokens(text: string): Uint16Array / decodeTokens(tokens: Uint16Array | number[]): string

Lossless subword BPE encoding (lemma_tok_encode) and string reconstruction (lemma_tok_decode).

LemmaIndex

In-memory lexical search index backed by C lemma_db_t:

LemmaLexicalAxis

Plug-and-play Text Axis adapter for the Corm Recall Kernel (@tty-pt/corm):

getLemmaWasm(): WebAssembly.Instance

Returns the WebAssembly instance loaded on the Stele shared-memory substrate.


4. Dual-Engine Runtime


5. C Development Headers & Native Integration

CFLAGS += -I./node_modules/@tty-pt/lemma/include
LDLIBS += -llemma

License

BSD-2-Clause — Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.

Documentation