Giter Club home page Giter Club logo

rust-sensitive's Introduction

🚫 rust-sensitive

build

English | 中文

Sensitive word filtering, support multiple data source loading, multiple filtering algorithms, multiple operation functions

🌟 Feature

  • Supports a wide range of operating functions
    • filter() returns the filtered text.
    • replace() Returns the text after replacing sensitive words.
    • is_sensitive() Returns whether the text contains sensitive words.
    • find_one() Returns the first sensitive word matched.
    • find_all() returns all the sensitive words matched.
  • Support multiple data sources loading
    • ✅ Support memory storage
    • 🔲 Support mysql storage
    • 🔲 Support mongo storage
  • Support multiple filtering algorithms
    • DFA Use HashMap to match sensitive words.
    • AC automated machine

⚙ Usage

first use

    use rust_sensitive::model::DfaSensitiveWordMap;

    fn test(){
        // Initialize the sensitive_map
        let map =DfaSensitiveWordMap::init_dfa_dic_from_file("./data.txt");
        /* because use once_cell,you can use 
         DfaSensitiveWordMap::get_dfa_dic() 
         to get the sensitive_map 
        */

        /*
        if use ac algorithm,you can use
        use rust_sensitive::model::AcSensitiveWordMap;

        let map =AcSensitiveWordMap::init_ac_dic_from_file("./data.txt"); 
        and because use once_call,you can also use
        AcSensitiveWordMap::get_ac_dic()
        to get the sensitive_map
        */
    }
    fn test2(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        // let map = AcSensitiveWordMap::get_ac_dic();
    }

filter()

    fn filter(&self, text_copy: &str) -> String
    // "hello" is sensitive word
    fn test(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        let result = map.filter("hello,world!");
        println!("{}",result); //",world"

    }

replace()

    replace(&self, text_copy: &str, repl: &str) -> String
    // "hello" is sensitive word
    fn test(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        let result = map.replace("hello,world!","*");
        // repl is like "!"、"*".a single word
        println!("{}",result); //"*****,world"

    }

is_sensitive()

    fn is_sensitive(&self, text: &str) -> bool
    // "hello" is sensitive word
    fn test(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        let result = map.is_sensitive("hello,world!");
        println!("{}",result); //"true"

    }

find_one()

    fn find_one(&self, text: &str) -> String
    // "hello" is sensitive word
    fn test(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        let result = map.find_one("hello,world!");
        println!("{}",result); //"hello"

    }

find_all()

    find_all(&self, text: &str) -> Vec<String>
    // "hello" "world" are sensitive words
    fn test(){
        let map = DfaSensitiveWordMap::get_dfa_dic();
        let result = map.find_all("hello,world!");
        println!("{}",result); //"hello","world"

    }

✔ Get

Run the following Cargo command in your project directory:

    cargo add rust_sensitive

Or add the following line to your Cargo.toml:

    [dependencies]
    rust_sensitive = "1.1.0"

📌 TODO

  • add mongo data source support
  • add bloom algorithm

rust-sensitive's People

Contributors

wqwqzzz avatar

Stargazers

houseme avatar lin jinxing avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.