https://github.com/houseme/sensitive-rs
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.
https://github.com/houseme/sensitive-rs
dict filter rust sensitive sensitive-data sensitive-word sensitive-word-filter trie trie-tree
Last synced: about 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/houseme/sensitive-rs
- Owner: houseme
- License: apache-2.0
- Created: 2024-08-16T05:12:26.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-04-08T02:45:57.000Z (about 2 months ago)
- Last Synced: 2025-04-08T03:31:13.749Z (about 2 months ago)
- Topics: dict, filter, rust, sensitive, sensitive-data, sensitive-word, sensitive-word-filter, trie, trie-tree
- Language: Rust
- Homepage: https://houseme.github.io/sensitive-rs
- Size: 434 KB
- Stars: 12
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Sensitive-rs
English [中文](README_CN.md)
[](https://github.com/houseme/sensitive-rs/actions?query=workflow%3ABuild)
[](https://crates.io/crates/sensitive-rs)
[](https://docs.rs/sensitive-rs/)
[](./LICENSE-APACHE)
[](https://crates.io/crates/sensitive-rs)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`:
```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
```rust
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
```rust
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](https://docs.rs/sensitive-rs).
## License
Licensed under either of
* Apache License, Version 2.0, [LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0
* MIT license [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MITat 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.