10 个不稳定版本 (4 个破坏性更新)
0.5.2 | 2022 年 8 月 13 日 |
---|---|
0.5.1 | 2022 年 8 月 10 日 |
0.4.0 | 2022 年 7 月 31 日 |
0.3.1 | 2022 年 6 月 2 日 |
0.1.0 | 2021 年 1 月 5 日 |
#507 在 文本处理
每月下载量 69 次
在 3 crates 中使用
3MB
74 行
thesaurus-rs
Rust 的离线同义词库,可以使用 wordnet 和 moby 同义词库。
将以下内容添加到 Cargo.toml
以使用 wordnet
thesaurus = "0.5"
将以下内容添加到 Cargo.toml
以仅使用 moby (wordnet 和静态默认启用)
thesaurus = { version = "0.5", features = ["moby","static"], default_features = false }
Crate 功能 "static
"
static
是默认启用的功能,将同义词词典存储在运行时内存中。这使得在初始化后对 dict
和 synonyms
的调用速度提高了 2.5-3 倍,但缺点是内存使用增加。要关闭 static
,请使用 default_features = false
选项。
后端比较
名称 | 简单示例二进制大小 | 简单示例二进制大小(去除) | 可用单词 | 平均同义词数量 | 压缩词典大小 | 许可证 |
---|---|---|---|---|---|---|
Moby | 15M | 11M | 30159 | 83.287 | 11M | US 公共领域 |
Wordnet | 6.9M | 3.4M | 125701 | 3.394 | 2.9M | Wordnet 许可证 |
基本示例
use std::{env, process};
fn main() {
let args = env::args().collect::<Vec<String>>();
let word: String = match args.get(1) {
Some(word) => word.to_string(),
None => {
eprintln!("Must include a word as an argument");
process::exit(1);
}
};
let synonyms = thesaurus::synonyms(&word);
let num_words = thesaurus::dict().len();
cfg_if::cfg_if! {
if #[cfg(all(feature = "moby", feature = "wordnet"))] {
print!("both wordnet and moby have ");
} else if #[cfg(feature = "moby")] {
print!("moby has ");
} else if #[cfg(feature = "wordnet")] {
print!("wordnet has ");
}
}
println!("{num_words} words indexed, and {} synonyms for \"{word}\"...", synonyms.len());
println!("synonyms...");
for x in &synonyms {
println!(" {x}");
}
}
Wordnet 输出
$ cargo r -rq --example simple -- good
wordnet has 125701 words indexed, and 107 synonyms for "good"...
synonyms...
acceptable
adept
advantageous
ample
angelic
angelical
bang-up
beatific
beneficial
beneficial
best
...
Moby 输出
$ cargo r -rq --example simple --no-default-features --features=moby -- good
moby has 30195 words indexed, and 666 synonyms for "good"...
synonyms...
able to pay
absolutely
acceptable
accomplished
according to hoyle
ace
actual
adept
adequate
admirable
admissible
adroit
advantage
advantageous
...
两者输出
$ cargo r -rq --example simple --features=moby,wordnet -- good
both wordnet and moby have 132592 words indexed, and 773 synonyms for "good"...
synonyms...
able to pay
absolutely
acceptable
acceptable
accomplished
according to hoyle
ace
actual
adept
adept
adequate
admirable
admissible
adroit
...