16个版本

0.3.3 2023年12月25日
0.3.2 2023年12月25日
0.2.0 2023年12月25日
0.1.10 2023年12月25日

#150WebAssembly

Download history 18/week @ 2024-03-10 2/week @ 2024-03-17 63/week @ 2024-03-24 2/week @ 2024-03-31

每月 127 次下载

MIT/Apache

86KB
1.5K SLoC

strprox

strprox是一个库,目前允许进行top-k字符串自动补全。

旨在实现Deng等人在论文中提出的top-k "基于匹配的错误容忍自动补全"框架算法(见引用

目录

示例

use strprox::Autocompleter;

fn main() {
    // Here's the data that the autocompleter uses
    let source = vec![
        "success",
        "successive",
        "successor",
        "decrease",
        "decreasing",
        "decrement",
    ];
    let autocompleter = Autocompleter::new(&source);
    let query = "luck";

    // Retrieve the 3 best strings for autocompletion
    let result = autocompleter.autocomplete(query, 3);

    // The prefix edit distance is the best edit distance between a full string and
    // all the prefixes of another (refer to the paper by Deng et al.).
    //
    // Here the PED is between the query and the prefixes of the autocomplete strings.

    // (string: success, PED: 2)
    // (string: successive, PED: 2)
    // (string: successor, PED: 2)
    for measured_prefix in &result {
        println!("{}", measured_prefix);
    }

    // Collect the strings from the resulting string and prefix edit distance combination
    let result_strings: Vec<&str> = result
        .iter()
        .map(|measured_prefix| measured_prefix.string.as_str())
        .collect();

    assert_eq!(result_strings, vec!["success", "successive", "successor"]);
}

说明

Autocompleter当前是一个泛型结构体,为了空间效率,默认将引用字符串的长度限制为u8::MAX,并将引用字符串的最大数量限制为u32::MAX。以后可以添加宏来为其他无符号类型实例化它。

一些测试需要名为words.txt的文件(高亮链接),位于src/tests

引用

@article{10.14778/2977797.2977808,
author = {Deng, Dong and Li, Guoliang and Wen, He and Jagadish, H. V. and Feng, Jianhua},
title = {META: An Efficient Matching-Based Method for Error-Tolerant Autocompletion},
year = {2016},
issue_date = {June 2016},
publisher = {VLDB Endowment},
volume = {9},
number = {10},
issn = {2150-8097},
url = {https://doi.org/10.14778/2977797.2977808},
doi = {10.14778/2977797.2977808},
journal = {Proc. VLDB Endow.},
month = {jun},
pages = {828–839},
numpages = {12}
}

此论文也可从会议网站此处获取。

许可

双许可协议下MITApache-2.0。您可以选择任一许可。

贡献

对此项目的贡献也理解为在MIT和Apache-2.0下双许可。

依赖关系

~0–350KB