Web 演示页面用 graphviz 画 lattice,需自行安装 graphviz;Docker 基础镜像不含 graphviz,做可视化要另找示例镜像;作为 Go 库使用时词典在独立的 kagome-dict 包中,需额外 go get 对应词典模块
kagome
ikawahaMIT活跃维护纯 Go 编写的独立日语形态素分析器,无需外部词典即可完成分词与词性标注,适合在 Go 服务里直接集成日文 NLP 能力。
Self-contained Japanese Morphological Analyzer written in pure Go
go install github.com/ikawaha/kagome/v2@latestREADME 未说明,纯 Go 实现且词典嵌入二进制,未提及 GPU 或显存要求
纯 Go 编写的自包含日语形态素分析器,把日文分词和词性标注直接嵌进二进制
纯 Go 编写的独立日语形态素分析器,无需外部词典即可完成分词与词性标注,适合在 Go 服务里直接集成日文 NLP 能力。
核心能力
- 内置 MeCab-IPADIC 与 UniDic 词典,无需外部词典文件
- 提供 normal/search/extended 三种切分模式
- 支持命令行、Go 库、C 库 FFI 与 WebAssembly 多种调用方式
- 内置 RESTful 服务模式,常驻进程避免重复加载词典
- 附带 lattice 可视化与长句切分等调试辅助命令
容易踩的坑
- v2.11.0最新正式版2026-03-03 · 2026-03-03 14:34 UTC
What's Changed
- chore(deps): bump actions/setup-go from 6.1.0 to 6.2.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/379
- docs: add missing "%" syntax in README.md by @KEINOS in https://github.com/ikawaha/kagome/pull/380
- chore(deps): bump actions/checkout from 6.0.1 to 6.0.2 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/382
- add example to use kagome as a C library from Python & PHP (via FFI) by @KEINOS in https://github.com/ikawaha/kagome/pull/381
- chore(deps): bump docker/login-action from 3.6.0 to 3.7.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/383
- chore(deps): bump goreleaser/goreleaser-action from 6.4.0 to 7.0.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/384
- chore(deps): bump actions/setup-go from 6.2.0 to 6.3.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/385
- chore(ci): skip coveralls failure while service is down by @ikawaha in https://github.com/ikawaha/kagome/pull/386
- feat(server): redesign demo UI with real-time lattice and zoom by @ikawaha in https://github.com/ikawaha/kagome/pull/387
Full Changelog: https://github.com/ikawaha/kagome/compare/v2.10.3...v2.11.0
- v2.10.32026-01-03 · 2026-01-03 08:06 UTC
查看更新说明
What's Changed
- chore(deps): bump goreleaser/goreleaser-action from 6.2.1 to 6.3.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/352
- chore(deps): bump actions/setup-go from 5.4.0 to 5.5.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/357
- chore(deps): bump docker/setup-buildx-action from 3.10.0 to 3.11.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/358
- chore(deps): bump docker/setup-buildx-action from 3.11.0 to 3.11.1 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/359
- chore(deps): bump docker/login-action from 3.4.0 to 3.5.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/362
- chore(deps): bump actions/checkout from 4.2.2 to 5.0.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/363
- chore(deps): bump goreleaser/goreleaser-action from 6.3.0 to 6.4.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/364
- chore(deps): bump actions/setup-go from 5.5.0 to 6.0.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/365
- chore(deps): bump docker/login-action from 3.5.0 to 3.6.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/366
- fix: #367 Update and refactor README.md by @KEINOS in https://github.com/ikawaha/kagome/pull/368
- docs: change word delimiter from space to slash in examples by @ikawaha in https://github.com/ikawaha/kagome/pull/370
- Release candidate by @ikawaha in https://github.com/ikawaha/kagome/pull/369
- chore(deps): bump docker/setup-qemu-action from 3.6.0 to 3.7.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/372
- chore(deps): bump actions/checkout from 5.0.0 to 5.0.1 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/373
- chore(deps): bump actions/checkout from 5.0.1 to 6.0.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/374
- chore(deps): bump actions/setup-go from 6.0.0 to 6.1.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/375
- chore(deps): bump actions/checkout from 6.0.0 to 6.0.1 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/376
- chore(deps): bump docker/setup-buildx-action from 3.11.1 to 3.12.0 by @dependabot[bot] in https://github.com/ikawaha/kagome/pull/377
- chore: Bump kagome-dict from v1.1.6 to v1.1.7 by @ikawaha in https://github.com/ikawaha/kagome/pull/378
Full Changelog: https://github.com/ikawaha/kagome/compare/v2.10.2...v2.10.3
- v2.10.22025-04-01 · 2025-04-01 13:54 UTC
查看更新说明
What's Changed
- chore(deps): bump reviewdog/action-golangci-lint from 2.7.1 to 2.7.2 by @dependabot in https://github.com/ikawaha/kagome/pull/345
- chore(deps): bump reviewdog/action-golangci-lint from 2.7.2 to 2.8.0 by @dependabot in https://github.com/ikawaha/kagome/pull/346
- fix: typo and enhance documentation by @KEINOS in https://github.com/ikawaha/kagome/pull/347
- chore: golangci-lint migration by @ikawaha in https://github.com/ikawaha/kagome/pull/348
- chore: Update kagome-dict and fix Go version by @ikawaha in https://github.com/ikawaha/kagome/pull/356
Full Changelog: https://github.com/ikawaha/kagome/compare/v2.10.1...v2.10.2
- v2.10.12025-03-12 · 2025-03-12 11:56 UTC
查看更新说明
What's Changed
- fix: release badge failure (false positive status) by @KEINOS in https://github.com/ikawaha/kagome/pull/341
- fix: links "sample" --> "_examples" in README by @KEINOS in https://github.com/ikawaha/kagome/pull/342
- chore: Bump kagome-dict from v1.1.0 to v1.1.1 (ipa/v1.2.1, uni/v1.2.1) by @ikawaha in https://github.com/ikawaha/kagome/pull/344
Full Changelog: https://github.com/ikawaha/kagome/compare/v2.10.0...v2.10.1
- v2.10.02024-08-03 · 2024-08-03 07:51 UTC
查看更新说明
What's Changed
- feat: Add standard ja filter by @ikawaha in https://github.com/ikawaha/kagome/pull/339
- Release candidate by @ikawaha in https://github.com/ikawaha/kagome/pull/340
Full Changelog: https://github.com/ikawaha/kagome/compare/v2.9.11...v2.10.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Kagome v2
Kagome is an open source Japanese morphological analyzer written in pure Go. It can tokenize Japanese text into words and analyze parts of speech, with dictionaries embedded in the binary for easy deployment.
[!NOTE] Key features (Improvements from v1):
- Self-contained binaries with embedded dictionaries (MeCab-IPADIC, UniDic)
- Multiple segmentation modes for different use cases
- RESTful API server mode for production use
- WebAssembly support for browser environments
- C library API for FFI integration (Python, PHP, and other languages)
Index
- Basic Usage
- Install
- Commands
- Dictionaries
- Segmentation modes
- Docker
- WebAssembly
- Use from other languages (FFI)
- Reference
- License
Basic Usage
Command line
% kagome -h
Japanese Morphological Analyzer -- github.com/ikawaha/kagome/v2
usage: kagome <command>
The commands are:
[tokenize] - command line tokenize (*default)
server - run tokenize server
lattice - lattice viewer
sentence - tiny sentence splitter
version - show version
tokenize [-file input_file] [-dict dic_file] [-userdict user_dic_file] [-sysdict (ipa|uni)] [-simple false] [-mode (normal|search|extended)] [-split] [-json]
-dict string
dict
-file string
input file
-json
outputs in JSON format
-mode string
tokenize mode (normal|search|extended) (default "normal")
-simple
display abbreviated dictionary contents
-split
use tiny sentence splitter
-sysdict string
system dict type (ipa|uni) (default "ipa")
-udict string
user dict
% # piped standard input
% echo "すもももももももものうち" | kagome
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
- For more details, see the Commands section.
As a Go library
You can integrate Kagome into your Go applications as follows:
# Install Kagome module
go get github.com/ikawaha/kagome/v2
package main
import (
"fmt"
"strings"
"github.com/ikawaha/kagome-dict/ipa"
"github.com/ikawaha/kagome/v2/tokenizer"
)
func main() {
t, err := tokenizer.New(ipa.Dict(), tokenizer.OmitBosEos())
if err != nil {
panic(err)
}
// wakati (simple word splitting/segmentation)
fmt.Println("---wakati---")
seg := t.Wakati("すもももももももものうち")
fmt.Println(seg)
// tokenize w/ morphological analysis
fmt.Println("---tokenize---")
tokens := t.Tokenize("すもももももももものうち")
for _, token := range tokens {
features := strings.Join(token.Features(), ",")
fmt.Printf("%s\t%v\n", token.Surface, features)
}
}
output:
---wakati---
[すもも も もも も もも の うち]
---tokenize---
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
As a C library
Kagome is written in pure Go but can be compiled as a C shared library and used from other languages via FFI (Foreign Function Interface).
See the "Use from other languages (FFI)" section below for details and examples.
More examples
We provide various examples demonstrating how to use Kagome in different scenarios:
Install
To get the kagome command line tool, choose your preferred installation method below:
-
Go (recommended)
go install github.com/ikawaha/kagome/v2@latest -
Homebrew
# macOS and Linux (for both AMD64 and Arm64) brew install ikawaha/kagome/kagome -
Manual Install
- For manual installation, download and extract the appropriate archived file for your OS and architecture from the releases page.
- Note that the extracted binary must be placed in an accessible directory with execution permission.
-
Docker/Docker Compose
- See the Docker section below
Commands
Major sub-commands of kagome command line tool.
Tokenize command
% # interactive/REPL mode
% kagome
すもももももももものうち
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
% # piped standard input
% echo "すもももももももものうち" | kagome
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
% # JSON output
% # (For jq command see https://jqlang.org/)
% echo "猫" | kagome -json | jq .
[
{
"id": 286994,
"start": 0,
"end": 1,
"surface": "猫",
"class": "KNOWN",
"pos": [
"名詞",
"一般",
"*",
"*"
],
"base_form": "猫",
"reading": "ネコ",
"pronunciation": "ネコ",
"features": [
"名詞",
"一般",
"*",
"*",
"*",
"*",
"猫",
"ネコ",
"ネコ"
]
}
]
% # word splitting/segmentation only (equivalent to "wakati" functionality)
% echo "すもももももももものうち" | kagome -json | jq -r '[.[].surface] | join("/")'
すもも/も/もも/も/もも/の/うち
% # Extract only pronunciations using jq (for Text-to-Speech purposes, etc.)
% echo "私ははにわよわわわんわん" | kagome -json | jq -r '.[].pronunciation'
ワタシ
ワ
ハニワ
ヨ
ワ
ワ
ワンワン
Server command
For continuous usage, kagome provides a server mode to decouple the startup time of the tokenizer.
RESTful API
Start a server and try to access the "/tokenize" endpoint.
% kagome server &
% curl -XPUT localhost:6060/tokenize -d'{"sentence":"すもももももももものうち", "mode":"normal"}' | jq .
Web App
Start a server and access http://localhost:6060 in your browser.
% kagome server &
[!IMPORTANT] The demo web application uses graphviz to draw a lattice. You need graphviz to be installed on your system.
[!TIP] Kagome can be compiled to WebAssembly (wasm) and run locally in a web browser as well. For details, see the WebAssembly section.
- Wasm Demo: https://ikawaha.github.io/kagome/
Lattice command
A debug tool of tokenize process outputs a lattice in graphviz dot format.
% kagome lattice 私は鰻 | dot -Tpng -o lattice.png

Sentence command
Split long text into sentences:
% echo "吾輩は猫である。名前はまだ無い。" | kagome sentence
吾輩は猫である。
名前はまだ無い。
This command is useful if a single line of data is too lengthy, and you want to avoid errors such as bufio.Scanner: token too long.
% echo "吾輩は猫である。名前はまだ無い。" | kagome -json | jq -r '[.[].surface] | join("/")'
吾輩/は/猫/で/ある/。/名前/は/まだ/無い/。
% echo "吾輩は猫である。名前はまだ無い。" | kagome sentence | kagome -json | jq -r '[.[].surface] | join("/")'
吾輩/は/猫/で/ある/。
名前/は/まだ/無い/。
This command is equivalent to the -split option of the tokenize command.
% echo "吾輩は猫である。名前はまだ無い。" | kagome -split -json | jq -r '[.[].surface] | join("/")'
吾輩/は/猫/で/ある/。
名前/は/まだ/無い/。
Dictionaries
-
Currently supported dictionaries by default.
dict source package MeCab IPADIC mecab-ipadic-2.7.0-20070801 github.com/ikawaha/kagome-dict/ipa UniDIC unidic-mecab-2.1.2_src github.com/ikawaha/kagome-dict/uni -
Experimental Features
dict source package mecab-ipadic-NEologd mecab-ipadic-neologd github.com/ikawaha/kagome-ipa-neologd Korean MeCab mecab-ko-dic-2.1.1-20180720 github.com/ikawaha/kagome-dict-ko
[!NOTE] For more details and differences between the dictionaries, see the wiki.
Segmentation modes
Similar to Kuromoji, Kagome also supports various segmentation modes (splitting strategies) to tokenize the input text.
- Normal: Regular segmentation
- Search: Use a heuristic to perform additional segmentation that is useful for search purposes
- Extended: Similar to search mode, but also unknown words with uni-grams
| Untokenized | Normal | Search | Extended |
|---|---|---|---|
| 関西国際空港 | 関西国際空港 | 関西 国際 空港 | 関西 国際 空港 |
| 日本経済新聞 | 日本経済新聞 | 日本 経済 新聞 | 日本 経済 新聞 |
| シニアソフトウェアエンジニア | シニアソフトウェアエンジニア | シニア ソフトウェア エンジニア | シニア ソフトウェア エンジニア |
| デジカメを買った | デジカメ を 買っ た | デジカメ を 買っ た | デ ジ カ メ を 買っ た |
[!NOTE] If your purpose is for search, try changing the mode before switching to another dictionary.
Docker
We provide scratch-based Docker images that simply run the kagome command line tool on various architectures: AMD64, Arm64, Arm32 (Arm v5, v6 and v7)
-
Pull the image
docker pull ikawaha/kagome:latest# Alternatively, you can pull from GitHub Container Registry docker pull ghcr.io/ikawaha/kagome:latest -
Run the command via Docker
# Interactive/REPL mode docker run --rm -it ikawaha/kagome:latest# If pulling from GitHub Container Registry docker run --rm -it ghcr.io/ikawaha/kagome:latest -
Run the server via Docker
# Server mode (http://localhost:6060) docker run --rm -p 6060:6060 ikawaha/kagome:latest server# If pulling from GitHub Container Registry docker run --rm -p 6060:6060 ghcr.io/ikawaha/kagome:latest server -
docker-compose.ymlexampleservices: kagome: image: ikawaha/kagome:latest ports: ["6060:6060"] command: server restart: unless-stopped
Note: Base image doesn't include Graphviz. For lattice visualization, see examples.
WebAssembly
Kagome compiles to WebAssembly for browser use.
- Live demo: https://ikawaha.github.io/kagome/
- Source code: ./_examples/wasm
Use from other languages (FFI)
Kagome is written in pure Go but can be compiled as a C shared library and used from other languages via FFI (Foreign Function Interface).
- Currently supported/tested languages:
- Python 3.12+ (using
ctypes) - PHP 8+ (using
FFI)
- Python 3.12+ (using
# Python example using ctypes
from libkagome import Kagome
kagome = Kagome()
tokens = kagome.tokenize("すもももももももものうち")
for token in tokens:
print(f"{token.surface}\t{token.pos}")
<!-- PHP example using FFI -->
<?php
declare(strict_types=1);
require __DIR__ . '/libkagome.php';
$kagome = new Kagome();
$tokens = $kagome->tokenize("すもももももももものうち");
foreach ($tokens as $token) {
echo "{$token->surface}\t" . implode(',', $token->pos) . "\n";
}
For complete examples and build instructions, see:
- ./_examples/clib/ - C library FFI examples for Python and PHP
[!NOTE] The C library provides thread-safe tokenization with proper memory management and includes comprehensive tests.
Reference
-
Detailed Reference Manual in Japanese:
-
Community Wiki in English:
License
- MIT
