User Dictionary
Use a user dictionary when a domain-specific word should be treated as one token or needs an explicit part of speech or base form.
Quick Start
Without a dictionary, 生成AI (generative AI) splits into two tokens. One TSV row joins it:
import { Suzume } from '@libraz/suzume'
const suzume = await Suzume.create()
const show = () => suzume.analyze('生成AIで要約した').map((m) => m.surface).join(' | ')
console.log(show()) // 生成 | AI | で | 要約 | し | た
const count = suzume.loadUserDictionary('生成AI\tNOUN\n')
console.log(count) // 1
console.log(show()) // 生成AI | で | 要約 | し | た
suzume.destroy()Try your own rows here. The demo analyzes the same text with and without the dictionary:
Source Format
The source format is tab-separated text, one entry per line. Every loader and suzume-cli dict compile / dict validate read this one layout:
surface<TAB>POS[<TAB>conj_type][<TAB>base_form]| Field | Required | Description |
|---|---|---|
surface | Yes | Text matched by the dictionary |
POS | Yes | Part of speech |
conj_type | No | Conjugation type or proper-name marker |
base_form | No | Base form; leave conj_type empty when only a base form is needed |
This example registers a noun, a verb whose forms are expanded, and a noun with an explicit base form, one per row:
生成AI NOUN
もふる VERB GODAN_RA
スマホ NOUN スマートフォンEach row changes the analysis of a sentence:
| Row | Sentence | Without the row | With the row |
|---|---|---|---|
生成AI NOUN | 生成AIで要約した | 生成 / AI / で / 要約 / し / た | 生成AI / で / 要約 / し / た |
もふる VERB GODAN_RA | 猫をもふった | 猫 / を / も / ふっ / た | 猫 / を / もふっ / た (もふっ has base form もふる) |
スマホ NOUN (base form スマートフォン) | スマホを買った | スマホ has base form スマホ | スマホ has base form スマートフォン |
Use actual tab characters between fields. Blank lines and lines whose first non-whitespace character is # are ignored.
At runtime and when compiling to .dic, each entry after conjugation expansion can have at most 255 UTF-8 bytes in its surface and at most 255 in its base form. The surface cannot contain a NUL byte (U+0000).
Part-of-speech Values
POS is matched exactly, including case: NOUN loads, noun fails with Invalid POS at line N: noun. Each part of speech accepts the names in its row.
| Part of speech | Accepted names |
|---|---|
| Noun | NOUN, PROPN, PROPER_NOUN, 名詞 |
| Verb | VERB, 動詞 |
| Adjective | ADJ, ADJECTIVE, 形容詞 |
| Adverb | ADV, ADVERB, 副詞 |
| Particle | PARTICLE, 助詞 |
| Auxiliary | AUX, AUXILIARY, 助動詞 |
| Conjunction | CONJ, CONJUNCTION, 接続詞 |
| Adnominal adjective | DET, DETERMINER, ADNOMINAL, 連体詞 |
| Pronoun | PRON, PRONOUN, 代名詞 |
| Prefix | PREFIX, 接頭辞 |
| Suffix | SUFFIX, 接尾辞 |
| Interjection | INTJ, INTERJECTION, 感動詞 |
| Symbol | SYMBOL, SYM, 記号 |
| Other or phrase | OTHER, PHRASE, その他 |
PROPN and PROPER_NOUN create a noun with the proper-noun classification: a ミカヅキ堂 row gives the token ミカヅキ堂 the extended POS NOUN_固有 in ミカヅキ堂へ行く, where a NOUN row gives NOUN. An interjection row takes the interjection conjugation type automatically.
Closed-class entries
PARTICLE and AUX are accepted, but each row produces a warning. Grammatical particles and auxiliaries normally belong in Suzume's built-in layer (L1) rather than a user dictionary.
Conjugation Types
Set conj_type to describe conjugation or a more specific grammatical class. Matching verbs and i-adjectives generate inflected entries from the base form.
| Value | Use |
|---|---|
ICHIDAN | Ichidan verb |
GODAN_KA, GODAN_GA, GODAN_SA, GODAN_TA | Godan verb in the corresponding row |
GODAN_NA, GODAN_BA, GODAN_MA, GODAN_RA, GODAN_WA | Godan verb in the corresponding row |
SURU, KURU | Irregular verb |
I_ADJ, NA_ADJ | I-adjective or na-adjective |
INTJ | Interjection marker |
FAMILY, GIVEN | Family-name or given-name marker |
NONE | No conjugation type; the same as an empty field |
conj_type is matched exactly, including case. Besides the names above, the PascalCase spellings Ichidan, GodanKa, GodanGa, GodanSa, GodanTa, GodanNa, GodanBa, GodanMa, GodanRa, GodanWa, Suru, Kuru, IAdjective, NaAdjective, Interjection, ProperFamily, ProperGiven, and None are accepted, along with INTERJECTION, PROPER_FAMILY, and PROPER_GIVEN. A verb or i-adjective with a matching marker expands into its inflected forms, and each form becomes its own runtime entry.
The proper-name and na-adjective markers change the label of the token instead of adding forms:
| Row | Sentence | Token | Effect |
|---|---|---|---|
榊原 NOUN FAMILY | 榊原さんが来た | 榊原 | NOUN_姓 (a NOUN row gives NOUN) |
朔也 NOUN GIVEN | 朔也くんが来た | 朔也 | NOUN_名 (a NOUN row gives NOUN) |
ゆるふわ ADJ NA_ADJ | ゆるふわな服 | ゆるふわ | ADJ_NA (an ADJ row without a marker gives ADJ_終止) |
NA_ADJ does not expand: one row installs one entry.
A third field that is not a marker is read as the base form. A misspelled or lowercase marker such as suru therefore loads without a warning, as a base form, and no forms are expanded. A numeric third field is an error (see Removed Layouts); a numeric base form goes in the fourth column with the third left empty, as in 一<TAB>NOUN<TAB><TAB>1.
How to pick conj_type
Find the class from the dictionary form. See godan and ichidan for the verb distinction.
| Entry | POS | conj_type | Class |
|---|---|---|---|
| 食べる | VERB | ICHIDAN | Ichidan verb: 食べない, 食べます |
| 書く | VERB | GODAN_KA | Godan verb ending in く: 書かない, 書きます |
| 話す | VERB | GODAN_SA | Godan verb ending in す: 話さない, 話します |
| 点検する | VERB | SURU | Noun + する; see what a SURU row changes |
| 高い | ADJ | I_ADJ | I-adjective: 高くない |
| 静か | ADJ | NA_ADJ | Na-adjective: 静かな |
A wrong pick fails silently: the row loads with no error and no warning, but expands into the wrong forms, as the ICHIDAN row in the figure above shows. After loading, analyze a conjugated sentence and check the user-dictionary flag.
What a SURU Row Changes
Without a row, built-in analysis keeps a suru-verb as a noun followed by する: 点検する gives 点検 (NOUN) / する (VERB), and 点検した gives 点検 / し (VERB, base form する) / た. A 点検する VERB SURU row installs whole-word entries only for some forms. 点検する, 点検すれば, 点検しろ and 点検せよ each become one VERB token with base form 点検する and the user-dictionary flag, while 点検した, 点検します and 点検しない split as 点検 / し / ….
Removed Layouts
Rows in the older layouts are not converted or ignored. Each of these fails the whole load as a parse error, in every loader and in suzume-cli dict compile / dict validate. N is the line number:
| Row shape | Error text |
|---|---|
Comma-delimited rows, for example 生成AI,NOUN,5000 | Removed legacy CSV layout at line N; use tab-separated rows |
Numeric third column, for example 生成AI<TAB>NOUN<TAB>5000 | Removed cost column at line N: column 3 is numeric; rows are surface, POS[, conj_type][, base_form] |
| Four or more columns with a numeric fourth column after a non-empty third column that is not a conjugation type | Removed legacy TSV layout at line N: column 4 is a numeric cost; rows are surface, POS[, conj_type][, base_form] |
A malformed quoted field fails with Invalid quoting at line N: <detail>, where the detail is unterminated quoted field or unexpected character after closing quote. A row with a non-empty third column that is not a conjugation type and a non-empty fourth column fails with Ambiguous non-empty TSV columns 3 and 4 at line N.
Runtime Loading
Each successful call adds another source or binary dictionary to the same instance. The CLIs apply each repeatable --dictionary (-d) argument to the instance used by that command.
import { Suzume, SuzumeError } from '@libraz/suzume'
const suzume = await Suzume.create()
const source = '生成AI\tNOUN\nもふる\tVERB\tGODAN_RA\n'
try {
const expandedCount = suzume.loadUserDictionary(source)
console.log(expandedCount)
} catch (error) {
if (error instanceof SuzumeError) {
console.error(error.message)
}
throw error
} finally {
suzume.destroy()
}from suzume import Suzume, SuzumeError
source = "生成AI\tNOUN\nもふる\tVERB\tGODAN_RA\n"
with Suzume() as suzume:
try:
expanded_count = suzume.load_user_dictionary(source)
except SuzumeError as error:
print(error)
raisepackage main
import (
"fmt"
"log"
"github.com/libraz/go-suzume"
)
func main() {
analyzer, err := suzume.New()
if err != nil {
log.Fatal(err)
}
defer analyzer.Close()
source := []byte("生成AI\tNOUN\nもふる\tVERB\tGODAN_RA\n")
expandedCount, err := analyzer.LoadUserDictionary(source)
if err != nil {
log.Fatal(err)
}
fmt.Println(expandedCount)
}#include "suzume/suzume.hpp"
#include <iostream>
int main() {
auto tokenizer = suzume::Tokenizer::create();
if (!tokenizer) {
std::cerr << tokenizer.error().message << "\n";
return 1;
}
const auto expanded_count =
tokenizer->loadUserDictionary("生成AI\tNOUN\nもふる\tVERB\tGODAN_RA\n");
if (!expanded_count) {
std::cerr << expanded_count.error().message << "\n";
return 1;
}
std::cout << *expanded_count << "\n";
return 0;
}#include "suzume/suzume_c.h"
#include <stdio.h>
#include <string.h>
int main(void) {
suzume_t tokenizer = suzume_create();
if (!tokenizer) {
fprintf(stderr, "%s\n", suzume_last_error());
return 1;
}
const char* source = "生成AI\tNOUN\nもふる\tVERB\tGODAN_RA\n";
const size_t expanded_count =
suzume_load_user_dictionary(tokenizer, source, strlen(source));
if (expanded_count == 0) {
fprintf(stderr, "%s\n", suzume_last_error());
suzume_destroy(tokenizer);
return 1;
}
printf("%zu\n", expanded_count);
suzume_destroy(tokenizer);
return 0;
}# user.tsv contains the same tab-separated rows.
# -d / --dictionary is repeatable and also accepts compiled .dic files.
suzume --dictionary user.tsv "生成AIで要約した" # Python wheel
suzume-cli analyze --dictionary user.tsv "生成AIで要約した" # native CLIReturn Values and Errors
| Binding | Source dictionary result | Failure details |
|---|---|---|
| JavaScript | loadUserDictionary() returns the installed-entry count | Throws SuzumeError (code, operation, message) |
| Python | load_user_dictionary() returns the installed-entry count | Raises SuzumeError |
| Go | LoadUserDictionary() returns (int, error) | *suzume.Error with Code, Op, and Message |
| C++ | loadUserDictionary() returns Expected<std::size_t> | error() on the result carries code, message, and operation |
| C ABI | suzume_load_user_dictionary() returns the installed-entry count | A return of 0 is a failure; read suzume_last_error() / suzume_last_error_code() |
| CLI | Exits with status 1 when a dictionary cannot be loaded | Prints <prog>: error: failed to load dictionary: <path>: <native text> to standard error |
The binary loaders (loadBinaryDictionary() and its equivalents) return the installed-entry count the same way. Failure is an exception or an error value in every binding except the C ABI, which returns 0. A successful source load always installs at least one entry. The count is measured after conjugation expansion and duplicate removal, not by counting source rows.
message is the native text unchanged. A malformed source is a parse error (code 4), and an empty source fails with Empty dictionary data (code 6, invalid input). Loading 生成AI,NOUN,5000 gives:
Removed legacy CSV layout at line 1; use tab-separated rowsThe JavaScript and Python loaders take the source as text or as its UTF-8 bytes: a Uint8Array in JavaScript, and bytes, bytearray or memoryview in Python. Bytes that are not valid UTF-8 fail with Dictionary entry is not valid UTF-8 at line N (code 4). Any other argument type is rejected with invalid dictionary: <value> (expected a string or binary data): a SuzumeError with code 6 in JavaScript, a ValueError in Python.
A failed source or binary load does not remove or replace dictionaries already installed on the instance. It also does not install the valid prefix of a source file. Successful loads remain additive until they are cleared or the instance is destroyed.
Warnings and Partially Valid Input
Runtime source loading skips a record with fewer than two fields. If another row is valid, the valid rows are installed and the skipped row is recorded as a warning:
missing-pos
生成AI NOUNIf at least one entry installs, the runtime loader skips any expanded entries that fail the field checks and records Skipped N invalid dictionary entries. To check a source file before loading it, run suzume-cli dict validate. Both dict validate and dict compile report the affected source lines and exit with status 1 when an expanded entry fails these checks.
Warnings from runtime loads are appended to the instance's dictionary-warning list:
| Binding | Read warnings |
|---|---|
| JavaScript | dictionaryWarnings |
| Python | dictionary_warnings |
| Go | DictionaryWarnings() |
| C++ | Tokenizer::dictionaryWarnings() |
| C ABI | suzume_dictionary_warning_count() and suzume_dictionary_warning() |
| CLIs | Printed to standard error as warning: <text> after each -d / --dictionary load |
clearUserDictionaries() and its equivalents clear runtime-load warnings but retain construction-time warnings.
If parsing succeeds but no entries can be installed, the load fails with Dictionary source contains no loadable entries (code 4). Unknown POS values, empty required fields, invalid UTF-8, malformed quoting, the removed layouts, and non-empty columns after the fourth cause the entire source load to fail during parsing.
Dictionary Layers
The layers are numbered L1 to L4, and other pages use these names:
| Layer | Holds | Comes from |
|---|---|---|
| L1 | Built-in grammar inventory: particles, auxiliaries, conjunctions, determiners, pronouns, formal nouns, interjections | Compiled into the library |
| L2 | Core vocabulary | core.dic |
| L3 | Bundled user dictionary | user.dic |
| L4 | Caller-loaded dictionaries | Runtime loading calls |
All four layers are consulted at every position, and no layer hides another layer's entries. L1 is always present, core.dic and user.dic load automatically when the instance is created, and L4 stays until it is cleared or the instance is destroyed. Entries from L3 and L4 receive a score bonus, which is why a user-dictionary row usually wins over the split it replaces. It does not always win: see When a Row Does Not Win.
Tokens from both user-dictionary layers report the user-dictionary flag. The npm package, the PyPI wheel, and the Go binding embed or ship core.dic and user.dic, so no setup is needed.
Where core.dic and user.dic are read from depends on the binding:
| Binding | Source of core.dic and user.dic |
|---|---|
| JavaScript | Embedded in the WASM module only. There is no data-directory option and no environment variable |
| Python | The wheel's bundled data directory only. SUZUME_DATA_DIR and ~/.suzume are not consulted, and there is no data_directory argument |
| Go | Options.DataDirectory when set. With default options, Go passes the embedded copies staged at startup. If SUZUME_DATA_DIR is set at instance creation or the embedded files could not be staged, the core uses its native search order. See the Go guide |
| C++ and C | data_directory when set, exclusively; otherwise the first directory that holds each file among SUZUME_DATA_DIR, ~/.suzume, the install data directory, /usr/local/share/suzume, /usr/share/suzume and ./data. A build configured with SUZUME_EMBED_DICT=ON embeds both files and reads no path or variable |
| Native CLI | The same search as C++, without a data-directory flag; see Environment Variables |
The skip options apply only when an instance is created. Clearing removes every source and binary dictionary loaded on that instance and leaves the other three layers in place:
| Binding | Skip core.dic | Skip bundled user.dic | Clear caller-loaded dictionaries |
|---|---|---|---|
| JavaScript | skipCoreDictionary: true | skipBundledUserDictionary: true | clearUserDictionaries() |
| Python | skip_core_dictionary=True | skip_bundled_user_dictionary=True | clear_user_dictionaries() |
| Go | Options.SkipCoreDictionary | Options.SkipBundledUserDictionary | ClearUserDictionaries(), which returns error |
| C++ | Options::skip_core_dictionary | Options::skip_bundled_user_dictionary | clearUserDictionaries(), which returns Expected<void> |
| C ABI | skip_core_dictionary in suzume_options_t | skip_bundled_user_dictionary in suzume_options_t | suzume_clear_user_dictionaries(handle) |
| CLI | --skip-core-dictionary | --skip-bundled-user-dictionary | Not needed; dictionaries last for one invocation |
--skip-bundled-user-dictionary skips only the bundled user.dic; files passed with --dictionary still load.
Verifying a Match
A token reports whether it came from a user dictionary, including the bundled one:
| Binding | Flag |
|---|---|
| JavaScript | isUserDict |
| Python | is_user_dict |
| Go | IsUserDict |
| C++ | is_user_dict |
| C ABI | SUZUME_MORPHEME_USER_DICT flag |
Splitting a Compound
An unmatched run of kanji such as 東京都庁前 stays one token in every mode. Registering its parts splits it:
東京 NOUN
都庁 NOUN
前 NOUN| Input | Without the rows | With the rows |
|---|---|---|
| 東京都庁前 | 東京都庁前 | 東京 / 都庁 / 前 |
| 東京都庁前を歩く | 東京都庁前 / を / 歩く | 東京 / 都庁 / 前 / を / 歩く |
In search mode, or with mergeCompounds, the three nouns merge back into 東京都庁前.
When a Row Does Not Win
A row wins when the path through it has a lower total cost than every competing path. It loses when another path costs less. A row for 都庁 alone leaves 東京都庁前 whole, because the single token that covers the whole run costs less than a path through 東京 + 都庁 + 前. To find out why, check these in order:
- Read the user-dictionary flag on the tokens. If no token has it, the row did not take part in the chosen path.
- With the native CLI,
suzume-cli analyze --compare -d rows.tsv "東京都庁前"prints the analysis without the rows, with them, and the difference.No structural differencemeans the rows changed nothing. suzume-cli analyze --debug -d rows.tsv "東京都庁前"writes the lattice candidates to standard error, with their costs and a[dict:user]mark on user-dictionary candidates, and the best path.- Register the neighbouring pieces too, as in the table above, or a longer entry that spans the boundary you need: a single
都庁前row gives東京/都庁前. - Lower
unary.user_dict_bonus(default -2.0) throughscorerOptions. With -4 a lone都庁row splits東京都庁前. The change applies to every user-dictionary entry.
--compare and --debug exist in the native CLI only.
Binary Dictionaries
Compile source TSV when startup time matters or when the same dictionary will be loaded repeatedly. Compiling needs the native suzume-cli, which the npm package and the PyPI wheel do not include.
suzume-cli dict compile user.tsv # writes user.dicThe C ABI loads the same bytes with suzume_load_binary_dictionary(), which returns the installed-entry count. See dict in the Native CLI reference for the compiler and the file layout.
Persistence
Caller-loaded dictionaries live in the instance and disappear when it is destroyed. Store the TSV source or compiled .dic in your application, then load it into each new instance.
Recommended Practice
- Use canonical TSV with literal tab characters.
- Add only words whose current tokenization or part of speech needs an override.
- Supply
conj_typefor verbs and adjectives that need inflected forms. - Check the expanded-entry count or binding-specific error after each load.
- Analyze a representative sentence and inspect the user-dictionary flag.
See Also
- API Reference for dictionary methods, errors, warnings, and morpheme fields.
- C / C++ Library for the C++ wrapper and stable C ABI.
- Python API for Python return types and exceptions.
- Go Bindings for the cgo API.
- Native CLI for compiling, inspecting, and loading dictionary files.