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文本处理

Download history 21/week @ 2024-03-12 45/week @ 2024-03-19 13/week @ 2024-03-26 46/week @ 2024-04-02 77/week @ 2024-04-09 7/week @ 2024-04-16 21/week @ 2024-04-23 97/week @ 2024-04-30 22/week @ 2024-05-07 30/week @ 2024-05-14 40/week @ 2024-05-21 38/week @ 2024-05-28 41/week @ 2024-06-04 9/week @ 2024-06-11 8/week @ 2024-06-18 7/week @ 2024-06-25

每月下载量 69 次
3 crates 中使用

MIT 许可证

3MB
74

thesaurus-rs

Crates.io Crates.io API

Rust 的离线同义词库,可以使用 wordnetmoby 同义词库。

将以下内容添加到 Cargo.toml 以使用 wordnet

thesaurus = "0.5"

将以下内容添加到 Cargo.toml 以仅使用 moby (wordnet 和静态默认启用)

thesaurus = { version = "0.5", features = ["moby","static"], default_features = false }

Crate 功能 "static"

static 是默认启用的功能,将同义词词典存储在运行时内存中。这使得在初始化后对 dictsynonyms 的调用速度提高了 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
...

依赖项