4 个版本
0.2.1 | 2020 年 3 月 17 日 |
---|---|
0.2.0 | 2020 年 2 月 20 日 |
0.1.1 | 2020 年 2 月 16 日 |
0.1.0 | 2020 年 2 月 15 日 |
#1675 在 文本处理
240KB
8K SLoC
sudachiclone-rs - 使用 Rust 的 SudachiPyClone
sudachiclone-rs 是 Sudachi 的 Rust 版本,Sudachi 是一个日语形态分析器。
安装 CLI
设置.1 安装 sudachiclone
sudachiclone 从 crates.io 发布。您可以通过在命令行中执行 cargo install sudachiclone 来安装 sudachiclone。
$ cargo install sudachiclone
设置.2 安装字典
默认字典包 SudachiDict_core 从 WorksAppliations 下载站点发布。运行 pip install 如下
$ pip install https://object-storage.tyo2.conoha.io/v1/nc_2520839e1f9641b08211a5c85243124a/sudachi/SudachiDict_core-20200127.tar.gz
使用 CLI
安装 sudachiclone 后,您也可以通过命令 sudachiclone 在终端中使用它。
您可以通过这种方式使用 sudachiclone 执行标准输入
$ sudachiclone
sudachiclone
有 4 个子命令(默认:tokenize
)
$ sudachiclone -h
Japanese Morphological Analyzer
USAGE:
sudachiclone [SUBCOMMAND]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
build Build Sudachi Dictionary
help Prints this message or the help of the given subcommand(s)
link Link Default Dict Package
tokenize Tokenize Text
ubuild Build User Dictionary
$ sudachiclone tokenize -h
sudachiclone-tokenize
Tokenize Text
USAGE:
sudachiclone tokenize [FLAGS] [OPTIONS] [in_files]...
FLAGS:
-h, --help (default) see `tokenize -h`
-a print all of the fields
-d print the debug information
-V, --version Prints version information
-v print sudachipy version
OPTIONS:
-o <fpath_out> the output file
-r <fpath_setting> the setting file in JSON format
-m <mode> the mode of splitting [possible values: A, B, C]
ARGS:
<in_files>... text written in utf-8
$ sudachiclone link -h
sudachiclone-link
Link Default Dict Package
USAGE:
sudachiclone link [OPTIONS]
FLAGS:
-h, --help see `link -h`
-V, --version Prints version information
OPTIONS:
-t <dict_type> dict dict [default: core] [possible values: small, core, full]
$ sudachiclone build -h
sudachiclone-build
Build Sudachi Dictionary
USAGE:
sudachiclone build [FLAGS] [OPTIONS] -m [in_files]
FLAGS:
-h, --help see `build -h`
-m connection matrix file with MeCab's matrix.def format
-V, --version Prints version information
OPTIONS:
-d <description> description comment to be embedded on dictionary [default: ]
-o <out_file> output file (default: system.dic) [default: system.dic]
ARGS:
<in_files> source files with CSV format (one of more)
作为 Rust 包
这里是一个使用示例
use sudachiclone::prelude::*;
let dictionary = Dictionary::new(None, None).unwrap();
let tokenizer = dictionary.create();
// Multi-granular tokenization
// using `system_core.dic` or `system_full.dic` version 20190781
// you may not be able to replicate this particular example due to dictionary you use
for m in tokenizer.tokenize("国家公務員", &Some(SplitMode::C), None).unwrap() {
println!("{}", m.surface());
};
# => 国家公務員
for m in tokenizer.tokenize("国家公務員", &Some(SplitMode::B), None).unwrap() {
println!("{}", m.surface());
};
# => 国家
# => 公務員
for m in tokenizer.tokenize("国家公務員", &Some(SplitMode::A), None).unwrap() {
println!("{}", m.surface());
};
# => 国家
# => 公務
# => 員
// Morpheme information
let m = tokenizer.tokenize("食べ", &Some(SplitMode::A), None).unwrap().get(0).unwrap();
println!("{}", m.surface());
# => 食べ
println!("{}", m.dictionary_form());
# => 食べる
println!("{}", m.reading_form());
# => タベ
println!("{:?}", m.part_of_speech());
# => ["動詞", "一般", "*", "*", "下一段-バ行", "連用形-一般"]
// Normalization
println!("{}", tokenizer.tokenize("附属", &Some(SplitMode::A), None).unwrap().get(0).unwrap().normalized_form());
# => 付属
println!("{}", tokenizer.tokenize("SUMMER", &Some(SplitMode::A), None).unwrap().get(0).unwrap().normalized_form());
# => サマー
println!("{}", tokenizer.tokenize("シュミレーション", &Some(SplitMode::A), None).unwrap().get(0).unwrap().normalized_form());
# => シミュレーション
许可证
依赖关系
~9–12MB
~278K SLoC