#sensitive #trie #filter #generate #replace-verification

sensitive-rs

Sensitive word search, verification, filtering and replacement

6 releases

0.2.1 Sep 12, 2024
0.2.0 Sep 12, 2024
0.1.3 Sep 11, 2024
0.1.0 Aug 16, 2024

#465 in Encoding

Download history 137/week @ 2024-08-16 2/week @ 2024-08-23 308/week @ 2024-09-06 94/week @ 2024-09-13 11/week @ 2024-09-20 35/week @ 2024-09-27 6/week @ 2024-10-04

291 downloads per month

MIT/Apache

335KB
468 lines

Sensitive-rs

English 中文

Build crates.io docs.rs License Crates.io

Sensitive-rs is a Rust library for finding, validating, filtering, and replacing sensitive words. It provides efficient algorithms to handle sensitive words, suitable for various application scenarios.

Features

  • Find: Locate all sensitive words in a text.
  • Validate: Check if a text contains any sensitive words.
  • Filter: Remove sensitive words from a text.
  • Replace: Replace sensitive words in a text with specified characters.

Installation

Add the following dependency to your Cargo.toml:

[dependencies]
sensitive-rs = "0.1"

Usage Examples

Here are some examples of how to use Sensitive-rs:

Here is an example of how to use the Filter struct

use sensitive_rs::Filter;

fn main() {
    // Create a new Filter
    let mut filter = Filter::new();
    filter.add_word("bad");
    filter.add_word("worse");

    // Find sensitive words
    let result = filter.find_in("This is bad.");
    assert_eq!(result, (true, "bad".to_string()));

    // Validate text
    let result = filter.validate("This is worse.");
    assert_eq!(result, (true, "worse".to_string()));

    // Filter sensitive words
    let filtered_text = filter.filter("This is bad and worse.");
    assert_eq!(filtered_text, "This is  and .");

    // Replace sensitive words
    let replaced_text = filter.replace("This is bad and worse.", '*');
    assert_eq!(replaced_text, "This is *** and *****.");
}

Here is an example of how to use the Trie struct

use sensitive_rs::Trie;

fn main() {
    // Create a new Trie filter
    let filter = Trie::new();
    filter.add_word("bad");
    filter.add_word("worse");

    // Find sensitive words
    let result = filter.find_in("This is bad.");
    assert_eq!(result, Some("bad".to_string()));

    // Validate text
    let result = filter.validate("This is worse.");
    assert_eq!(result, Some("worse".to_string()));

    // Filter sensitive words
    let filtered_text = filter.filter("This is bad and worse.");
    assert_eq!(filtered_text, "This is  and .");

    // Replace sensitive words
    let replaced_text = filter.replace("This is bad and worse.", '*');
    assert_eq!(replaced_text, "This is *** and *****.");
}

Documentation

For detailed documentation, please refer to Documentation.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 or MIT license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–14MB
~156K SLoC