The MeCab Microservice provides RESTful API endpoints for Japanese morphological analysis using MeCab. It supports various output formats and analysis modes.
http://localhost:8081
No authentication is required for the API endpoints.
GET /health
Check the service health and version information.
Response:
{
"status": "healthy",
"version": "mecab of 0.996",
"timestamp": "2024-01-01T00:00:00Z"
}
POST /analyze
Perform standard morphological analysis on Japanese text.
Request Body:
{
"text": "日本語の文章を解析します"
}
Response:
{
"original_text": "日本語の文章を解析します",
"results": [
{
"surface": "日本語",
"pos": "名詞",
"pos_detail_1": "一般",
"pos_detail_2": "*",
"pos_detail_3": "*",
"conjugation": "*",
"conj_form": "*",
"base_form": "日本語",
"reading": "ニホンゴ",
"pronunciation": "ニホンゴ"
},
{
"surface": "の",
"pos": "助詞",
"pos_detail_1": "連体化",
"pos_detail_2": "*",
"pos_detail_3": "*",
"conjugation": "*",
"conj_form": "*",
"base_form": "の",
"reading": "ノ",
"pronunciation": "ノ"
}
]
}
POST /analyze/wakati
Perform word segmentation (わかち書き) on Japanese text.
Request Body:
{
"text": "日本語の文章を解析します"
}
Response:
{
"original_text": "日本語の文章を解析します",
"wakati": "日本語 の 文章 を 解析 します"
}
POST /analyze/yomi
Get the reading pronunciation (読み) of Japanese text.
Request Body:
{
"text": "日本語の文章を解析します"
}
Response:
{
"original_text": "日本語の文章を解析します",
"yomi": "ニホンゴノブンショウヲカイセキシマス"
}
POST /analyze/chasen
Get analysis results in ChaSen compatible format.
Request Body:
{
"text": "日本語の文章を解析します"
}
Response:
{
"original_text": "日本語の文章を解析します",
"results": [...],
"raw_output": "日本語\t名詞,一般,*,*,*,*,日本語,ニホンゴ,ニホンゴ\nの\t助詞,連体化,*,*,*,*,の,ノ,ノ\n..."
}
POST /analyze/nbest
Get multiple possible parsing results (N-best solutions).
Request Body:
{
"text": "今日もしないとね",
"n_best": 2
}
Response:
{
"original_text": "今日もしないとね",
"n_best": 2,
"results": [
[
{
"surface": "今日",
"pos": "名詞",
"...": "..."
}
],
[
{
"surface": "今日",
"pos": "名詞",
"...": "..."
}
]
]
}
POST /analyze/batch
Process multiple texts in a single request.
Request Body:
[
"最初の文章です",
"二つ目の文章です",
"三つ目の文章です"
]
Response:
{
"results": [
{
"original_text": "最初の文章です",
"results": [...]
},
{
"original_text": "二つ目の文章です",
"results": [...]
},
{
"original_text": "三つ目の文章です",
"results": [...]
}
]
}
{
"error": "Text is required"
}
{
"error": "MeCab execution failed"
}
Health Check:
curl http://localhost:8081/health
Basic Analysis:
curl -X POST http://localhost:8081/analyze \
-H "Content-Type: application/json" \
-d '{"text":"日本語のテストです"}'
Word Segmentation:
curl -X POST http://localhost:8081/analyze/wakati \
-H "Content-Type: application/json" \
-d '{"text":"太郎はこの本を二郎を見た女性に渡した"}'
N-Best Analysis:
curl -X POST http://localhost:8081/analyze/nbest \
-H "Content-Type: application/json" \
-d '{"text":"今日もしないとね", "n_best": 3}'
package main
import (
"encoding/json"
"fmt"
"net/http"
"time"
)
type MeCabClient struct {
BaseURL string
Client *http.Client
}
func NewMeCabClient(baseURL string) *MeCabClient {
return &MeCabClient{
BaseURL: baseURL,
Client: &http.Client{Timeout: 30 * time.Second},
}
}
func (c *MeCabClient) Analyze(text string) (map[string]interface{}, error) {
reqBody := map[string]interface{}{"text": text}
jsonData, _ := json.Marshal(reqBody)
resp, err := c.Client.Post(c.BaseURL+"/analyze", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
return result, nil
}
// Usage
func main() {
client := NewMeCabClient("http://localhost:8081")
result, _ := client.Analyze("日本語の文章")
fmt.Println(result)
}
No rate limiting is currently implemented. For production use, consider implementing rate limiting based on your requirements.
The service includes:
Logs are stored in ./mecab-service/logs/mecab-service.log with rotation configured.
Use the health endpoint to verify service status:
curl http://localhost:8081/health
Content type
Image
Digest
sha256:5f192ebf3…
Size
50.4 MB
Last updated
about 1 year ago
docker pull simooowann/mecab-service:mecab-0.996