3 个版本 (破坏性更新)
| 0.3.0 | 2022 年 8 月 14 日 | 
|---|---|
| 0.2.0 | 2022 年 8 月 12 日 | 
| 0.1.0 | 2022 年 8 月 4 日 | 
#24 in #spelling
11KB
112 行代码(不含注释)
urlchecker
一个简单的 URL 检查器,用于查找欺诈 URL 或最近的 URL,同时速度快(线程化)
一个基于 Peter Norvig 在 http://norvig.com/spell-correct.html 中描述的统计算法的拼写检查器。
使用需要两步过程
- 调用 url.train()一到多次,使用大量文本来训练语言模型
- 调用 url.correct(word)来检索指定的 URL 的修正(如果存在)
例如:-
use std::collections::HashMap;
use urlchecker::URL;
fn main() {
    let mut url = URL {
        letters: "1234567890._-@abcdefghijklmnopqrstuvwxyz".to_string(),
        url_counts: HashMap::new(),
    };
    url.train(
        "https://docs.rs/regex/latest/regex/ \
    https://norvig.com/spell-correct.html \
    https://doc.rust-lang.net.cn/stable/std/thread/fn.scope.html\
    https://docs.rs/urlchecker/latest/urlchecker/index.html",
    );
    println!("{:#?}", url);
    println!("{:#?}", url.correct("doks.rs"));
}
输出:-
URL {
    letters: "1234567890._-@abcdefghijklmnopqrstuvwxyz",
    url_counts: {
        "docs.rs": 2,
        "doc.rust-lang.org": 1,
        "norvig.com": 1,
    },
}
Some(
    "docs.rs",
)
灵感来自
依赖项
~2–3MB
~53K SLoC