Dictionaries
Pass an array of DictionarySource objects in the dictionaries option.
Dictionary sources are either compiled artifacts (FileDictionarySource) or
entry lists computed at runtime (MapDictionarySource). The default
reference-authorized policy ranks candidates by source role and explicit
dictionary relations. Use sourcePolicy: "ordered" for legacy array precedence.
Standard Korean Dictionary packages
@gukhanmun/stdict-fst and @gukhanmun/stdict-cdb both ship the bundled
Standard Korean Dictionary (標準國語大辭典) in different binary formats.
Both stdictFst() and stdictCdb() return a Promise<FileDictionarySource>.
Reuse a loaded dictionary
Call loadDictionary() once when several converters use the same dictionary.
Import it from the same package as load(): either @gukhanmun/wasm or
@gukhanmun/napi.
The handle captures the source's contents and role. Each converter retains its own reference and applies its own source order and options. Load a new handle to pick up source changes. Handles cannot be moved between backend instances; there is no process-wide dictionary cache.
Use GukhanmunLoadOptions to annotate options containing handles.
GukhanmunOptions and GukhanmunFactory still describe raw-source inputs.
Open Korean Dictionary packages
@gukhanmun/opendict-fst and @gukhanmun/opendict-cdb ship the Open Korean
Dictionary (우리말샘) as separate general (一般語), North Korean (北韓語),
dialect (方言), and archaic (옛말) category dictionaries. JavaScript presets
do not auto-load these packages, so pass the categories you want explicitly:
Use the CDB package when you want the same categories in CDB format:
Loanword spelling examples packages
@gukhanmun/loanwords-fst and @gukhanmun/loanwords-cdb provide the National
Institute of Korean Language's Loanword spelling examples dictionary. Both
"ko-kr" and "ko-kp" require explicit loading; presets never add it for you.
The official loaders identify reference and loanword sources, so their relative
order does not change which source class takes priority under the default
"reference-authorized" policy:
For CDB format, import loanwordsCdb from @gukhanmun/loanwords-cdb instead.
Both loaders return a Promise<FileDictionarySource> and work with
@gukhanmun/wasm and @gukhanmun/napi. Installing the package alone does not
change conversion; include its loader's result in dictionaries.
Custom dictionaries
A FileDictionarySource specifies the binary format and the data to load from:
The data field accepts:
Load from a URL
In a browser the URL is fetched with fetch(). In Node.js, Deno, and Bun a
file:// URL is read from disk.
Load from bytes
Load from a file path (Node.js/Deno/Bun)
Passing a plain string path in a browser throws GukhanmunError with code
"io".
Combining multiple dictionaries
Building a custom dictionary
The .gukfst and .gukcdb files loaded above are compiled artifacts, built
from a plain text table with the gukhanmun-mkdict tool. See
Building a custom dictionary
in the CLI guide for how to author and compile dictionary sources. When the
entries are computed at runtime rather than stored on disk, pass them directly
as shown in the next section.
Entries computed at runtime
A MapDictionarySource carries entries in memory. Use it when a caller
derives readings while building a document, in a browser, or in an edge runtime
where neither a TSV file nor gukhanmun-mkdict is available:
The fields mirror the Rust ReadingCandidate type plus the hanja key:
Entry lists default to the "override" role. Cooperating policies consider
them before reference and loanword sources for the same spelling and consumed
length; earlier overrides win. With sourcePolicy: "ordered", all sources
follow array precedence, so place the entry list before a compiled dictionary
to override that dictionary's keys in this mode.
Repeating a hanja key appends another reading instead of replacing the
earlier one. Several readings for one headword stay available to the engine,
which then selects one from a following particle when the particle is decisive:
preference decides the context-free default. List order never does: when two
readings share a preference, the tie is broken by reading spelling, so set
distinct preferences when the choice matters.
An empty entries list contributes nothing, which makes { entries: [] } a
convenient placeholder for a document without overrides.
Cooperating sources
The default reference-authorized policy keeps reference and loanword
candidate sets separate. A reference candidate authorizes a foreign form only
when the source dictionary explicitly records the relevant synonym or formal
redirect. The offline compiler intersects the permissions of every contributing
sense; a shared hanja key or reading alone grants no permission. Missing
evidence retains the reference form. Thus 東扶餘 reads 동부여, while the
reference entry for 香港 authorizes 홍콩.
The resolver ranks complete forms before applying particle evidence once to the
whole pool. An independent loanword can still match a particle even when it is
not the default: 平 reads 평, but 平를 can select 다이라를. Dictionary
preferences apply within each source; they are not comparable across sources.
The lattice objective is unchanged.
An authored override is exclusive for the same spelling and consumed length
under every cooperating policy. It does not remove a longer dictionary match.
For cooperating policies, referenceOnly removes independent loanwords from
eligibility but retains reference-authorized forms, including forms supplied by
a loanword dictionary.
Selected forms carry their own lexical identity, alias, positional form and
annotation marks. First-occurrence handling uses the reference anchor when a
reference authorizes a foreign form; homophone handling compares the reading
actually emitted. Source-aware dictionary matches keep separate annotation
boundaries, including matches next to fallback characters. This can change
parenthetical grouping compared with ordered.
Set the policy and eligibility on the converter:
Both file and entry descriptors accept
role: "override" | "reference" | "loanword". Entry descriptors default to
"override". File descriptors use the binary's embedded role when present,
otherwise "override"; an explicit role replaces that metadata. Official
loaders declare their roles. Overrides are considered before cooperating
sources regardless of their array position; earlier overrides win. Set
sourcePolicy: "ordered" to restore legacy array precedence for all
descriptors.
The standard CDB loader downloads stdict.cdb.gz and decompresses it before returning a dictionary descriptor. A custom URL can serve either gzip or raw CDB bytes. The npm package retains the raw stdict.cdb export.
Dictionary roles do not change the lattice scoring objective. The JavaScript bindings buffer the complete document before conversion; see Streaming API.