This document explains the dictionary system used by Kagome C++ for Japanese morphological analysis.
Kagome C++ uses morphological dictionaries to analyze Japanese text. The dictionary contains information about:
- Word entries: Known Japanese words and their variations
- Part-of-speech (POS) tags: Grammatical classifications
- Readings: Pronunciation information (hiragana/katakana)
- Features: Additional morphological attributes
- Connection costs: Weights for optimal path selection in the lattice
The default dictionary is based on the IPA (Information-technology Promotion Agency) dictionary, which is derived from the IPAdic project. This is the same dictionary format used by MeCab and the original Go kagome project.
The dictionary is stored as a binary file (ipa.dict) containing:
- Header: Metadata about dictionary version and structure
- Word entries: Compressed morphological data
- Connection matrix: Costs for connecting different POS types
- Feature definitions: POS tag definitions and feature sets
The Kagome C++ tokenizer searches for the dictionary in the following locations (in order):
./ipa.dict(current working directory) - Recommended for Rspamd./data/ipa/ipa.dict(relative to executable)../data/ipa/ipa.dict(relative to executable)../../data/ipa/ipa.dict(relative to executable)/usr/local/share/kagome/ipa.dict(system-wide installation)/usr/share/kagome/ipa.dict(distribution package)/opt/kagome/ipa.dict(optional installation)
The IPA dictionary uses a hierarchical POS tagging system with the following major categories:
- 名詞 (Noun): General nouns, proper nouns, pronouns
- 動詞 (Verb): Action words, copulas
- 形容詞 (Adjective): I-adjectives, na-adjectives
- 副詞 (Adverb): Manner, degree, time adverbs
- 助詞 (Particle): Case markers, topic markers
- 助動詞 (Auxiliary verb): Auxiliary and helping verbs
- 連体詞 (Adnominal): Pre-noun modifiers
- 接続詞 (Conjunction): Connecting words
- 感動詞 (Interjection): Exclamations
- 記号 (Symbol): Punctuation, symbols
- フィラー (Filler): Hesitation sounds
- その他 (Other): Miscellaneous, unknown words
Each main category has multiple sub-categories providing fine-grained classification:
名詞,一般,*,*,*,*,猫,ネコ,ネコ
名詞,代名詞,一般,*,*,*,私,ワタシ,ワタシ
名詞,固有名詞,人名,名,*,*,太郎,タロウ,タロー
動詞,自立,*,*,五段・ラ行,基本形,歩く,アルク,アルク
形容詞,自立,*,*,形容詞・イ段,基本形,美しい,ウツクシイ,ウツクシー
The dictionary provides two types of reading information:
- Reading (読み): Standard pronunciation in katakana
- Pronunciation (発音): Actual pronunciation accounting for sound changes
Each word entry includes comprehensive morphological features:
- Inflection type: How the word changes form
- Inflection form: Current form of the word
- Base form: Dictionary form of the word
- Reading: Pronunciation information
- Semantic information: Additional meaning-related data
# Clone the repository with dictionary
git clone <repository-url>
cd kagome-cxx
# Dictionary is included in data/ipa/ipa.dict
ls -la data/ipa/ipa.dict# Copy to the same directory as the plugin (recommended)
cp data/ipa/ipa.dict /path/to/kagome_rspamd_tokenizer.so.dir/ipa.dict
# Or install system-wide
sudo mkdir -p /usr/share/kagome
sudo cp data/ipa/ipa.dict /usr/share/kagome/# Install via package manager (when available)
sudo apt install kagome-dict-ipa
# Manual installation
sudo mkdir -p /usr/share/kagome
sudo cp data/ipa/ipa.dict /usr/share/kagome/
sudo chmod 644 /usr/share/kagome/ipa.dictThe IPA dictionary is licensed under a BSD-style license:
- Copyright: 2000-2007 Nara Institute of Science and Technology (NAIST)
- Copyright: 2008-2023 Information-technology Promotion Agency, Japan (IPA)
- License: BSD 3-Clause License (see
debian/copyrightfor full text)
The IPA dictionary license is compatible with:
- ✅ Apache 2.0 (this project's license)
- ✅ MIT License
- ✅ BSD Licenses
- ✅ Commercial use
- ✅ Distribution and modification
If the main IPA dictionary cannot be loaded, Kagome C++ uses a minimal fallback dictionary containing:
- Basic hiragana/katakana entries
- Common punctuation
- Essential POS tags for basic tokenization
Note: Fallback mode provides limited functionality and should only be used for debugging.
Future Enhancement: Support for user dictionaries is planned for future versions.
Planned features:
- User-defined word entries
- Custom POS tags
- Domain-specific vocabularies
- Dictionary priority levels
The IPA dictionary requires:
- Disk space: ~50MB (compressed binary format)
- Memory usage: ~100-150MB when loaded
- Loading time: 2-5 seconds on modern systems
- Dictionary caching: Loaded once per process and reused
- Memory mapping: Dictionary uses efficient memory mapping when possible
- Compression: Binary format reduces memory footprint compared to text format
Error: "Dictionary file not found"
Solutions:
- Verify dictionary file exists:
ls -la ipa.dict - Check file permissions:
ls -la ipa.dict(should be readable) - Copy to expected location:
cp data/ipa/ipa.dict ./
Error: "Dictionary file size invalid" or loading crashes
Solutions:
- Re-download dictionary:
git checkout data/ipa/ipa.dict - Verify file integrity:
file ipa.dict(should show "data") - Check available disk space
- Try system-wide installation location
Error: AddressSanitizer errors or segmentation faults during loading
Solutions:
- Fallback dictionary will be used automatically
- Increase available memory
- Check for conflicting libraries
- Report issue with specific error details
Error: Cannot read dictionary file
Solutions:
# Fix file permissions
chmod 644 ipa.dict
# For system installation
sudo chown root:root /usr/share/kagome/ipa.dict
sudo chmod 644 /usr/share/kagome/ipa.dict
# For Rspamd integration
sudo chown rspamd:rspamd /path/to/ipa.dict
chmod 644 /path/to/ipa.dict#include "kagome/dict/dict.hpp"
// Create dictionary
auto dict = kagome::dict::factory::create_ipa_dict();
// Check if dictionary is loaded
if (dict) {
std::cout << "Dictionary loaded successfully\n";
// Get dictionary statistics (if available)
// auto stats = dict->get_stats();
} else {
std::cout << "Dictionary loading failed\n";
}#include "kagome/dict/dict.hpp"
// Use specific dictionary path (planned feature)
// auto dict = kagome::dict::factory::create_ipa_dict("/custom/path/ipa.dict");- IPAdic: Original morphological dictionary project
- MeCab: Reference implementation and format specification
- Kagome (Go): Dictionary format and processing algorithms
- Nara Institute of Science and Technology (NAIST) for IPAdic
- Information-technology Promotion Agency (IPA) for ongoing maintenance
- ikawaha for the original kagome Go implementation
- MeCab project for dictionary format specification
- README.md - Main project documentation
- RSPAMD_INTEGRATION.md - Rspamd-specific setup
- CONTRIBUTING.md - Development guidelines
- Original kagome project - Go implementation