Files
petal/internal/lexicon/data.go
prosolis 60eba25fee Phase 9: ESL superpowers — Chinese gloss + tone-rewrite
Inline Chinese gloss (offline) and a "say it more naturally" / tone-rewrite,
the two ESL features for the Mandarin-speaking writer.

Gloss: embedded English→Chinese dictionary (gloss.json.gz, 57k common words
built from ECDICT via scripts/build_gloss.py). lexicon gains Gloss()/Result.Gloss
and a lightweight GET /api/gloss/{word}; the right-click WordCard leads with the
中文; GlossTip shows it on a 350ms hover (reuses wordAt, so CJK is never glossed).
Offline + instant, works with the LLM down.

Rewrite: selecting text pops a SelectionBubble (更自然 + the tone vocabulary);
picking a style calls POST /api/docs/:id/rewrite (llm.RunRewrite, stateless,
owner-scoped) and shows a RewritePreview (original→rewrite, accept/cancel/retry).
Accept applies it in-editor.

Tests added in lexicon and suggestions. go build/vet/test, tsc, vite all clean;
live smoke vs a fake vLLM verified gloss + rewrite + 400/404/502 paths.

Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
2026-06-26 00:07:26 -07:00

30 lines
1.3 KiB
Go

// Package lexicon serves offline word lookups — a Chinese gloss, a definition,
// and a list of synonyms for a single word — from public datasets compiled into
// the binary. Definitions come from the Wordset dictionary (modern, concise
// glosses with a part of speech and example, which read kindly for an ESL
// writer); synonyms come from the Moby Thesaurus; the Chinese gloss comes from
// ECDICT. All are gzipped JSON, decompressed lazily on first use so a writer who
// never looks up a word pays nothing.
package lexicon
import _ "embed"
// definitionsGz is the gzipped Wordset definitions map: word → [[pos, def,
// example], …], lowercase keys. Built by the data-prep step (see commit notes).
//
//go:embed data/definitions.json.gz
var definitionsGz []byte
// synonymsGz is the gzipped Moby thesaurus map: headword → [synonym, …],
// lowercase keys, capped per word to keep the popover (and the binary) small.
//
//go:embed data/synonyms.json.gz
var synonymsGz []byte
// glossGz is the gzipped English→Chinese gloss map: word → 中文 gloss, lowercase
// keys. Built from ECDICT (scripts/build_gloss.py), filtered to common words so
// an ESL writer who speaks Mandarin gets an instant translation on hover/lookup.
//
//go:embed data/gloss.json.gz
var glossGz []byte