Skip to content
sillsdevPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

PanGloss

A Rust morphological parsing engine — words in, morphemes out — built from a native port of HermitCrab's parser (the C# morphological engine used by SIL's FieldWorks/FLEx) and now running a propose-and-confirm FST architecture: a foma finite-state network compiled from the grammar proposes candidate analyses in microseconds, and the exact HermitCrab engine confirms each candidate. The FST can only ever cost speed, never correctness — a candidate the FST over-proposes is rejected by the confirmer, and the proposer is held to 100% recall (every analysis the full engine would find is always proposed).

Deployment domains

PanGloss is delivered in several capability profiles:

  • Inference — browser/WASM, word processors, and native C hosts load a precompiled one-file analysis package for bounded analysis, spell checking, and glossing.
  • Native build and diagnostics — FieldWorks and AI frameworks use the C ABI or CLI to import grammars, compile FST packages, audit compiler health, and assess grammar revisions with pg-assess.
  • Reference development tooling — source in this repository can compare selected words with the pinned C# Machine HermitCrab oracle for HC XML. It supports conformance investigation but is not distributed in the Runtime or SDK.

Developer-only diagnostic policy (current policy). --allow-unproven is a developer-build/test control, not a production CLI capability; a production build must hide and reject it. It may omit valid parses, so its output is never certified or published. Capability enforcement, managed internal budgets, worker isolation, bounded I/O, and the non-disableable absolute ceiling remain active for every compile. Error health evidence remains production-unready and Critical denotes a correctness gap.

WASM contains no grammar or FST compiler. It consumes artifacts produced by native tooling. C# HermitCrab is an explicit build-time authority check, never a runtime fallback. PanGloss emits structured reports and FieldWorks investigation handoffs; consuming applications own history, publication decisions, UI, and interactive debugging, and PanGloss never launches FieldWorks.

Code, build, test, and release

PanGloss treats a linguistic grammar like source code:

Development step PanGloss
Code LibLCM/HermitCrab grammar and stems
Build Compile an FST and bind matching Rust-HermitCrab data
Compiler output A build report with FST warnings, errors, thresholds, and resource evidence
Test Run a caller-supplied word set against that compiled model
Test output An immutable assessment report; use pg-assess to compare reports and review a grammar delta
Release Optionally write one .pgpack PanGloss Language Pack
Deploy Load the Language Pack into PanGloss Runtime

A Language Pack is a data-only plugin, never executable extension code. It contains the precompiled FST and matching runtime grammar data; the fixed Runtime supplies all behavior. Compilation can stay in memory for iterative assessment, and writing a release artifact is optional. Build and assessment reports remain separate; applications own baselines, test policy, history, installers, and UI.

How it works

grammar ──emit lexc──► foma compile ──► proposing FST          (once, at grammar load)

word ──FST propose──► candidate morpheme sequences ──HC confirm──► analyses

Two analysis engines exist:

  • The propose-and-confirm FST path (pg_foma::composite::FomaAnalyzer) described above is the performance path and the target of ongoing optimization. batch --engine=fst selects it explicitly in a foma-tools build. The compiler owns admission; refused grammars exit without fallback. fst-health and make-report provide grammar characterization and readiness reports.
  • pangloss batch defaults to the full HermitCrab search engine, ported line-for-line from C#. pangloss parse, serve, and generate also use HC. It serves as the reference the FST path is verified against, and as the trace-capable engine (--trace works only here).

Ingesting a grammar

PanGloss accepts a grammar in three forms, dispatched by file extension everywhere a grammar path is taken:

Extension What it is
.fwdata A FieldWorks project file, imported directly — no FieldWorks-side export step
.json A pg-snapshot project snapshot (PanGloss's own versioned JSON format)
.xml Legacy HermitCrab XML export (being sunset; kept for the existing test corpus)

Direct FieldWorks import (.fwdata)

.fwdata ──pg-fwdata──► Snapshot (pg-snapshot JSON) ──pg_grammar::compile_project──► Grammar
  • pg-fwdata streams the .fwdata XML (real projects run tens of MB — no whole-file DOM) into an engine-agnostic Snapshot. It is tolerant by design: dangling references, unrecognized morph types, and stale ad-hoc rules become ImportReport warnings, never a panic (FieldWorks' own C# HC exporter crashes on a stale MoMorphAdhocProhib that this importer logs and skips).
  • pg_grammar::compile_project compiles a snapshot into the same Grammar the legacy XML loader produces — a Rust port of FieldWorks' HCLoader.cs compilation semantics.
  • Import/compile warnings go to stderr, labeled, never stdout (batch TSV output is parity-sensitive).

To materialize the intermediate snapshot for inspection or faster reloads:

pangloss import <project.fwdata> <out.json>

pangloss grammar-health <project.fwdata> <report.json> --snapshot-out <out.json> (optionally with --facts-out/--facts-context) writes that same snapshot, and the facts database, from the one import that also yields the health report.

See docs/fwdata-import-plan.md for the architecture and the conformance gate that checks the fwdata pipeline's parses against the legacy XML oracle, and docs/snapshot-format.md for the snapshot format.

Building and running the FST

The proposing FST is compiled at grammar load when compile_analyzer is called from Rust — the emitter turns the grammar's lexicon, morphotactics, and (pre-expanded) phonology into foma lexc source and compiles it in-process with a pure-Rust foma (no external binaries, no artifacts to manage). Compile time is interactive-scale: milliseconds to a few seconds on the reference grammars. A foma-tools build can route a batch through the FST with explicit engine selection:

FST mode has no per-word deadline or process RSS bound. Use an external watchdog with a deadline and process memory ceiling. Proposal caps do not contain confirmation; a word can stall the batch or exhaust memory. Supervise each word in a child process when per-word containment is required, and report killed words as incomplete.

pangloss batch grammar.xml words.txt out.tsv --engine=fst --threads 1 --work-cap unbounded --word-mem-cap-mib 0 --capture-cap-mib unbounded --guess=false

This path refuses unadmitted grammars without fallback and appends engine/completion metadata. The HC controls above must be explicitly disabled because the FST cannot report their stops. FST proposal limits remain active. See the batch contract for supported options and containment limits. Binaries built without foma-tools give an explicit feature error. Release builds already enable foma-tools. fst-health/make-report provide grammar characterization and readiness reports.

Compare complete FST analysis sets with plain HC-Rust search on every word (build with foma-tools):

pangloss fst-verify <grammar> <words.txt> --out parity.tsv --json parity.json --word-timeout-ms 10000

The report records equal, missing, extra, or incomparable per occurrence, both difference directions by stable analysis identity, input hashes, engine build identity and effective options. Mismatches and FST construction refusals exit nonzero after writing evidence. Caps and timeouts are incomparable; inspect the totals before claiming full parity. This compares the two Rust pipelines; C# oracle replay remains separate. See the FST verification format for bounds and schemas.

Parse one word (the only engine parse runs is the default HermitCrab one):

pangloss parse <grammar> <word> [--gloss] [--natural-gloss=eng] [--realize-map=<path>] [--without <guid>[,<guid>...]] [--work-cap N|unbounded] [--word-timeout-ms N]

--without parses as if the named lexical entries, allomorphs, phonological rules, compound rules, affix templates or ad hoc co-occurrence rules were deleted, and batch takes it too (see docs/retire-format.md).

Plain parsing and ordinary tracing exit with failure when the HC engine reports capped, timed_out, or invalid_shape. The applicable flags appear on stderr; any printed signature is then diagnostic partial output. Complete hits and complete rejections keep the existing word\tsignature stdout format and successful exit. The default work cap is 5,000,000,000 work steps; --word-timeout-ms 0 requests an immediate deadline.

When snapshot or FieldWorks loading auto-creates phonology, stderr records each inferred segment or boundary and its compiler-owned evidence, plus unresolved or ambiguous source uses. This report is independent of warnings and leaves parse stdout unchanged.

For one-word diagnostics as a single JSON document, including the trace, result, work total, and existing timing statistics:

pangloss parse <grammar> <word> --trace --trace-format=json --trace-details

This mode is explicit and remains one word per invocation. Its JSON search envelope carries completion flags, including incomplete results. See The trace format for the envelope and timing semantics.

Batch a word list to TSV (the only engine batch runs is the default HermitCrab one):

pangloss batch <grammar> <words.txt> <out.tsv> [--work-cap N|unbounded] [--word-timeout-ms N] [--threads N] [--analyses analyses.jsonl]

--work-cap defaults to 5,000,000,000 work steps per word, a runaway guard (not a performance tuning knob) that makes every batch terminate deterministically. A work step is one charged unit of search, and a word's work is the total of its work steps; pass --work-cap N to tighten the limit or --work-cap unbounded to lift it entirely. A word that hits the cap writes a typed CAP row -- an incomplete outcome kept for inspection, never presented as a result. --step-cap, which counted analysis attempts, was removed and is refused like any unknown option.

Generate a surface form from morpheme ids (default engine):

pangloss generate <grammar> <root-morpheme-id> [other-morpheme-id ...]
pangloss generate <snapshot.json|project.fwdata|project.fwbackup> --request <request.json>

The positional form addresses HC XML <MorphemeId> values. --request addresses exact FieldWorks entryGuid/msaGuid pairs in an imported snapshot; request schema version 1 selects MSAs only and explicitly refuses non-null formGuid constraints. The request's morphemes array is generation order, which is not surface order. In one Swahili analysis, surface SM + stem + FV + RELSUF is requested as SM, RELSUF, FV. --requests <file.jsonl|-> answers one request per line, in the serve generate row shape, and an error row for a bad line. See docs/generation.md for the request schema and limits.

From Rust, the same path is pg_foma::composite::FomaAnalyzer:

let grammar = pg_grammar::load(&xml)?;                  // or compile_project(&snapshot)
let mut analyzer = pg_foma::composite::compile_analyzer(&grammar)?;
let outcome = analyzer.analyze_word("kufuna");          // propose + confirm
let outcomes = analyzer.analyze_words(&words);          // parallel confirm across words

Representative timings (2026-07-17, all landed optimizations, one desktop machine): Indonesian compiles in ~85 ms and averages ~0.7 ms/word; Sena compiles in ~225 ms and averages ~29 ms/word; Amharic compiles in ~5.7 s and averages ~41 ms/word (median ~1 µs — most words are rejected by the proposer outright — with a heavy tail). The analysis runtime also targets wasm32-unknown-unknown; that build loads a precompiled analysis package and deliberately excludes grammar and FST compilation.

For approved-analysis comparison, add --analyses analyses.jsonl to retain ordered source Form/MSA/InflType GUIDs alongside the TSV. Each word carries its own completion flags and partial findings; a stopped search remains INCOMPLETE even when approved readings were found. See the shared morphology contract for the closed schema and unavailable-source cases.

Optimize a grammar with stats

The default HermitCrab engine can collect opt-in statistics over a representative word list. The reports identify expensive object kinds, rules that repeatedly produce nothing, and rules that manufacture forms with no lexical root:

pangloss batch <grammar> <words.txt> out.tsv --stats --threads 1 --word-timeout-ms 1000 --cache <cache.sqlite3>
pangloss stats <grammar> --cache <cache.sqlite3> --group group
pangloss stats <grammar> --cache <cache.sqlite3> --group never-fires
pangloss stats <grammar> --cache <cache.sqlite3> --group object --sort no-root

See Optimize a grammar with PanGloss stats for the complete human- and AI-readable workflow, report semantics, drill-down filters, machine-readable output, and interpretation cautions.

The immutable SQLite contract is documented in Grammar facts format; schema v7 can attach one validated frozen batch run.

Discovering the CLI's own surface

pangloss --describe (or pangloss describe) prints every subcommand and flag main.rs actually dispatches on as JSON, including hidden internal subcommands (marked "hidden": true) -- useful for pinning an external test double to the real CLI surface rather than to prose documentation.

Layout

  • rust/ — the engine workspace (crate map in rust/README.md). Key crates: pg-grammar (XML/snapshot → Grammar), pg-fwdata + pg-snapshot (FieldWorks import), pg-foma (lexc emit, FST propose, confirm orchestration), pg-parse/pg-rules/pg-fst (the HermitCrab engine, used both standalone and as the confirmer), pg-cli (the pangloss binary), pg-wasm (browser build). pg-foma pins the official foma crate (crates.io, divvun/foma-rs) directly — the wasm32 SystemTime::now() abort this repo used to work around with an in-tree vendored copy is fixed upstream as of 0.4.0.
  • conformance/ — the pinned clone of sillsdev/fieldworks-parser-conformance (the conformance suite), fetched at the commit in conformance.commit by rust/tools/conformance.ps1; gitignored.
  • machine/ — the sillsdev/machine submodule, pinned for the C# hc.dll founding oracle that replays the suite; it no longer holds the fixtures.
  • samples/data/ — reference grammars (Amharic, Indonesian, Sena). Local-only and gitignored (real language data is never committed); the test suite skips corpus tests when they're absent.
  • docs/ — active plans (docs/fst-plan/, docs/fwdata-import-plan.md, docs/superpowers/specs/), the port audit (docs/hermitcrab-rust-port-audit.md), and historical planning documents under docs/history/.

Building

cd rust
cargo build --release
cargo test
cargo clippy --workspace --all-targets

On Windows the MSVC toolchain (x86_64-pc-windows-msvc) is required.

On a machine running many parallel worktrees (e.g. .claude/worktrees/*), prefer rust/tools/build.ps1 and rust/tools/test.ps1 (PowerShell) over calling cargo directly: they redirect CARGO_TARGET_DIR off the system drive, wire in sccache/cargo-nextest when installed, and gate concurrent builds across worktrees so many agents building at once don't thrash the machine. See the doc comment at the top of each script.

Origin and parity

rust/ began as a from-scratch Rust reimplementation of SIL.Machine.Morphology.HermitCrab, extracted from sillsdev/machine as a single squashed commit. The parity contract is the conformance oracle in machine/, not this repo's own history — PanGloss's internals are free to diverge as long as that oracle stays green. See docs/hermitcrab-rust-port-audit.md for what was ported and what's known to differ.

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages