Skip to main content
This is the internal subsystem that powers the myspellchecker build CLI command. It coordinates the full corpus-to-database transformation: segmenting text, counting frequencies, extracting N-grams, and inferring POS tags through a staged pipeline with resume support for large datasets. It is designed to handle large datasets (10GB+) by using sharding, intermediate binary formats (Arrow), and resume capabilities.

Usage

CLI Usage

The easiest way to use the pipeline is via the command line interface:

Python API Usage

You can also invoke the pipeline programmatically:

Architecture

The pipeline executes in 5 distinct steps. It tracks file modification times to skip steps that are already up-to-date (Resume Capability).
1

Ingestion

  • Input: Raw text files (.txt, .csv, .tsv, .json, .jsonl, .parquet).
  • Process:
    • Reads files in chunks.
    • Normalizes text (Unicode normalization).
    • Splits into shards for parallel processing.
  • Output: raw_shards/*.arrow (Apache Arrow files).
2

Segmentation

  • Input: raw_shards/*.arrow
  • Process:
    • Iterates through shards.
    • Segments text into sentences and syllables using the configured word_engine.
      • Default: "myword" (both PipelineConfig and CLI)
    • Applies POS tagging using the configured pos_tagger (Rule-Based, Viterbi, or Transformer).
  • Output: segmented_corpus.arrow
3

Frequency Building

  • Input: segmented_corpus.arrow
  • Process:
    • Counts occurrences of Syllables, Words, Bigrams, and Trigrams.
    • Calculates POS tag probabilities (Unigram/Bigram/Trigram).
    • Filters items below min_frequency.
  • Output: TSV files (e.g., word_frequencies.tsv, bigram_probabilities.tsv).
4

Packaging

  • Input: TSV frequency files.
  • Process:
    • Creates SQLite schema.
    • Bulk loads data using transactions.
    • Optimizes database indices (VACUUM, ANALYZE).
  • Output: Final SQLite .db file.
5

Enrichment

  • Input: The packaged SQLite .db file from Step 4.
  • Process:
    • Mines confusable pairs (phonetic/orthographic variants like aspiration swaps, medial swaps, nasal endings).
    • Detects compound confusions (words incorrectly split during segmentation).
    • Extracts collocations using PMI/NPMI scoring.
    • Tags words with register labels (formal/informal/neutral) based on marker co-occurrence.
  • Output: Enrichment tables added to the SQLite .db file (confusable_pairs, compound_confusions, collocations, register_tags).
  • Disable with --no-enrich on the CLI or enrich=False in PipelineConfig.

Configuration

The PipelineConfig class supports fine-tuning:

Incremental Updates

The pipeline supports Incremental Updates to add new data to an existing database without rebuilding from scratch:
This merges the new counts with the existing database statistics.
If corpus files are removed between incremental runs, the pipeline will log a warning listing the missing files. Data from deleted files persists in the database. Run a full (non-incremental) rebuild to clean up stale data.

Curated Lexicon Support

You can mark specific words as trusted/curated (is_curated=1) in the database using the --curated-input option:
The curated lexicon must be a CSV file with a word column header:
Priority hierarchy for is_curated flag:
  1. Words from POS seed file → is_curated=1 (with POS tags)
  2. Words from curated lexicon → is_curated=1
  3. Other corpus words → is_curated=0
Use the scripts/merge_vocabulary.py utility to prepare curated lexicons by merging and deduplicating vocabulary files from multiple sources. See Custom Dictionaries Guide for detailed usage examples.