v1.4.3Lexical SearchBSD-2-Clause

Accent-sensitive search tokenizer, inverted full-text index (pão ≠ pao), and recall kernel lexical axis with zero external locale or iconv dependencies. Canonical header is <ttypt/lemma.h>.

GitHub
git clone https://github.com/tty-pt/liblemma

liblemma logo

liblemma

npm C99 BSD-2-Clause FTS tokenizer Recall Kernel Lexical Axis

Accent-sensitive search tokenizer, inverted full-text index (pão ≠ pao), and recall kernel lexical axis with zero external locale or iconv dependencies. Canonical header is <ttypt/lemma.h>.

1. Quickstart

Index documents and query accent-sensitive prefixes in under 15 lines:

#include <stdio.h>
#include <stdint.h>
#include <ttypt/lemma.h>

int main(void) {
    // Open in-memory inverted index database
    lemma_db_t *db = lemma_open(0xFF);

    // Index song titles strictly preserving accents
    lemma_index(db, "title", "song_1", "Coração");
    lemma_index(db, "title", "song_2", "Pão de Açúcar");

    // Prefix search for "cora" matches "Coração" (accent preserved)
    int handled = 0;
    lemma_query(db, "title", "cora", 0, &handled);

    printf("Full-text index query executed (handled: %d)\n", handled);
    lemma_close(db);
    return 0;
}

Compile and link:

cc fts_demo.c $(pkg-config --cflags --libs liblemma) -o fts_demo

2. Core API Reference

The essential functions for tokenization and inverted index search:

FunctionSignatureDescription
lemma_openlemma_db_t *lemma_open(unsigned mask)Open in-memory inverted index table
lemma_indexint lemma_index(db, field, row_id, val)Tokenize and index a document field
lemma_queryuint32_t lemma_query(db, field, q, out_hd, &h)Prefix search matching word beginnings
lemma_query_phraseuint32_t lemma_query_phrase(db, f, phrase, out, &h)Contiguous multi-word exact phrase query
lemma_tok_encodesize_t lemma_tok_encode(const char *text, uint16_t *tokens, size_t max_tokens)Encode text into lossless subword BPE token IDs
lemma_tok_decodesize_t lemma_tok_decode(const uint16_t *tokens, size_t count, char *out, size_t outsz)Decode subword tokens back to original string
lemma_foldint lemma_fold(out, outsz, in)Lowercase ASCII and Latin-1 while keeping diacritics
rec_axis_fill_tokensint rec_axis_fill_tokens(db, field, q, phrase, set)Stream token matches into a sealed recall candidate set

👉 For differential un-indexing, phrase query mechanics, and recall ranking contexts, see include/ttypt/lemma.h.


3. Diacritic Preservation: Why Accents Matter

Standard ASCII folding collapses accented vowels (pão $\rightarrow$ pao), causing severe semantic collisions:

In Portuguese, pão means bread, while pao means stick/wood. In Spanish, año means year, while ano means anus.

liblemma lowercases ASCII and Latin-1 characters while strictly preserving diacritic identity:

Input TextStandard ASCII Foldinglemma_fold OutputSemantic Correctness
Pão (Bread)paopãoDistinct from pau or pao
Coração (Heart)coracaocoraçãoAccents preserved
München (Munich)munchenmünchenUmlaut preserved
Café (Coffee)cafecaféAcute accent preserved

Zero external dependencies: liblemma requires no iconv dynamic libraries and no operating system locale files (/etc/locale.gen).


4. corm CLI Multi-Axis Integration

liblemma attaches directly to the corm CLI tool as the @lemma text axis:

# Ingest document and index with liblemma:
corm -p "Traditional Portuguese bakery baking warm pão de queijo" docs.db@lemma:a:s

# Query accent-sensitive text via corm CLI:
corm -X "lemma" --lemma="pão" docs.db@lemma:a:s

liblemma also integrates into the wider stack:

  • Data Engine FTS: Powers accent-preserving full-text search across string fields in libhyle.
  • Recall Kernel (Text Axis): Matches stream directly into candidate sets via rec_axis_fill_tokens registered with libcorm (<ttypt/cormr.h>).

5. Installation & Build

Prebuilt Packages

Prebuilt packages for Linux (APT / Alpine / Arch / Fedora-RHEL), macOS (Homebrew), Windows (winget / MSYS2), and OpenBSD, and mobile static sysroots for Android (https://tty.pt/android/ — arm64-v8a, armeabi-v7a, x86_64) and iOS (https://tty.pt/ios/ — liblemma.xcframework) are distributed via tty.pt packages. Use liblemma as the package name.

Build from Source

Builds use shared libstele rules (include ttypt/include.mk):

make                  # builds lib/liblemma.so
make test             # run tokenization, property, and query tests
sudo make install     # install headers and library to system

6. JavaScript & WebAssembly Bindings (@tty-pt/lemma)

Official Node.js and Browser WebAssembly bindings are colocated in npm/:

  • Unicode Case Folding: Accurate case folding preserving language diacritics (Pão $\rightarrow$ pão, Straße $\rightarrow$ straße).
  • Instant Search-as-You-Type: Runs in browser inputs via pre-compiled WebAssembly (dist/lemma.wasm) with sub-millisecond execution.
  • C Development Headers: Install via npm install @tty-pt/lemma (from npm or https://tty.pt/npm/) and consume headers from node_modules/@tty-pt/lemma/include.

👉 For complete TypeScript usage, lexical search guides, and API reference, see npm/README.md.

License

BSD 2-Clause License. Copyright (c) 2026, tty-pt. See LICENSE.

Maintained by:tty-pt