https://github.com/mosuka/kuromoji-cli
A command-line interface for Lucene Kuromoji.
https://github.com/mosuka/kuromoji-cli
cli command-line java kuromoji lucene
Last synced: 3 months ago
JSON representation
A command-line interface for Lucene Kuromoji.
- Host: GitHub
- URL: https://github.com/mosuka/kuromoji-cli
- Owner: mosuka
- Created: 2020-03-02T02:52:26.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-06-27T03:37:06.000Z (almost 3 years ago)
- Last Synced: 2025-01-23T00:28:52.392Z (4 months ago)
- Topics: cli, command-line, java, kuromoji, lucene
- Language: Java
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kuromoji CLI
A Japanese morphological analysis command-line interface for [Lucene Kuromoji](https://github.com/apache/lucene-solr/tree/master/lucene/analysis/kuromoji).
## Build
### Build Requirement
- Java >= 1.17.0
- gradle >= 7.0.0### Build Kuromoji CLI
```shell
% ./gradlew build
```## Test
```shell
% ./gradlew test
```## Make JAR file
Combine dependent classes and resources into a single JAR file.
```shell
% ./gradlew shadowJar
```## Make distribution package
Archive executable script file and JAR file.
```shell
% ./gradlew archiveZip
```## Install Kuromoji CLI
```shell
% unzip ./build/distributions/kuromoji-cli-.zip
```## Usage
### Basic usage
You can easily tokenize the text and see the results as follows:
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji
関西国際空港 名詞,固有名詞,組織,*,*,*,関西国際空港,カンサイコクサイクウコウ,カンサイコクサイクーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,トートバッグ,*,*
EOS
```### Tokenize mode
Kuromoji-cli provides two tokenization modes: `normal`, `search` and `extended`.
#### Normal mode
`normal` mode tokenizes faithfully based on words registered in the dictionary. (Default):
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -m normal
関西国際空港 名詞,固有名詞,組織,*,*,*,関西国際空港,カンサイコクサイクウコウ,カンサイコクサイクーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,トートバッグ,*,*
EOS
```#### Search mode
`search` mode tokenizes a compound noun words additionally:
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -m search
関西 名詞,固有名詞,地域,一般,*,*,関西,カンサイ,カンサイ
国際 名詞,一般,*,*,*,*,国際,コクサイ,コクサイ
空港 名詞,一般,*,*,*,*,空港,クウコウ,クーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,トートバッグ,*,*
EOS
```#### Extended mode
`extended` mode tokenizes similar to search mode, but also unigram unknown words (experimental):
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -m extended
関西 名詞,固有名詞,地域,一般,*,*,関西,カンサイ,カンサイ
国際 名詞,一般,*,*,*,*,国際,コクサイ,コクサイ
空港 名詞,一般,*,*,*,*,空港,クウコウ,クーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
ト 記号,一般,*,*,*,*,ト,*,*
ー 記号,一般,*,*,*,*,ー,*,*
ト 記号,一般,*,*,*,*,ト,*,*
バ 記号,一般,*,*,*,*,バ,*,*
ッ 記号,一般,*,*,*,*,ッ,*,*
グ 記号,一般,*,*,*,*,グ,*,*
EOS
```### Output format
kuromoji-cli provides three output formats: `mecab`, `wakati` and `json`.
#### MeCab format
`mecab` outputs results in a format like MeCab:
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -o mecab
関西国際空港 名詞,固有名詞,組織,*,*,*,関西国際空港,カンサイコクサイクウコウ,カンサイコクサイクーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,トートバッグ,*,*
EOS
```#### Whietespace delimitation format
`wakati` outputs the token text separated by spaces:
```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -o wakati
関西国際空港 限定 トートバッグ
```#### JSON format
`json` outputs the token information in JSON format:```shell
% echo "関西国際空港限定トートバッグ" | ./bin/kuromoji -o json | jq .
[
{
"surface": "関西国際空港",
"attrs": [
"名詞",
"固有名詞",
"組織",
"*",
"*",
"*",
"関西国際空港",
"カンサイコクサイクウコウ",
"カンサイコクサイクーコー"
]
},
{
"surface": "限定",
"attrs": [
"名詞",
"サ変接続",
"*",
"*",
"*",
"*",
"限定",
"ゲンテイ",
"ゲンテイ"
]
},
{
"surface": "トートバッグ",
"attrs": [
"名詞",
"一般",
"*",
"*",
"*",
"*",
"トートバッグ",
"*",
"*"
]
}
]
```