Crates.io | word_sensitive |
lib.rs | word_sensitive |
version | 0.1.2 |
source | src |
created_at | 2021-06-07 06:38:33.696574 |
updated_at | 2021-06-11 09:56:03.707856 |
description | A library for sensitive string matching, the implementation language is rust, and the algorithm used is ac |
homepage | https://github.com/yangcancai/word_sensitive |
repository | https://github.com/yangcancai/word_sensitive/ |
max_upload_size | |
id | 407182 |
size | 337,649 |
A library for sensitive string matching, the implementation language is rust, and the algorithm used is ac
use word_sensitive::trie;
let mut tree = trie::Trie::default();
tree.add_key_word("aaa".as_bytes().to_vec());
tree.add_key_word("aab".as_bytes().to_vec());
tree.add_key_word("aac".as_bytes().to_vec());
tree.add_key_word("aba".as_bytes().to_vec());
tree.add_key_word("abb".as_bytes().to_vec());
tree.add_key_word("abc".as_bytes().to_vec());
tree.add_key_word("aca".as_bytes().to_vec());
tree.add_key_word("acb".as_bytes().to_vec());
tree.add_key_word("acc".as_bytes().to_vec());
tree.add_key_word("baa".as_bytes().to_vec());
tree.add_key_word("bab".as_bytes().to_vec());
tree.add_key_word("bac".as_bytes().to_vec());
tree.add_key_word("bba".as_bytes().to_vec());
tree.add_key_word("bbb".as_bytes().to_vec());
tree.add_key_word("bbc".as_bytes().to_vec());
tree.add_key_word("bca".as_bytes().to_vec());
tree.add_key_word("bcb".as_bytes().to_vec());
tree.add_key_word("bcc".as_bytes().to_vec());
tree.add_key_word("caa".as_bytes().to_vec());
tree.add_key_word("cab".as_bytes().to_vec());
tree.add_key_word("cac".as_bytes().to_vec());
tree.add_key_word("cba".as_bytes().to_vec());
tree.add_key_word("cbb".as_bytes().to_vec());
tree.add_key_word("cbc".as_bytes().to_vec());
tree.add_key_word("cca".as_bytes().to_vec());
tree.add_key_word("ccb".as_bytes().to_vec());
tree.add_key_word("ccc".as_bytes().to_vec());
tree.build();
let matches = tree.query("abcabcbcca".as_bytes().as_ref());
assert_eq!(matches[0], "abc".as_bytes().as_ref());
assert_eq!(matches[1], "bca".as_bytes().as_ref());
assert_eq!(matches[2], "cab".as_bytes().as_ref());
assert_eq!(matches[3], "abc".as_bytes().as_ref());
assert_eq!(matches[4], "bcb".as_bytes().as_ref());
assert_eq!(matches[5], "cbc".as_bytes().as_ref());
assert_eq!(matches[6], "bcc".as_bytes().as_ref());
assert_eq!(matches[7], "cca".as_bytes().as_ref());
use word_sensitive::trie;
let mut tree = trie::Trie::default();
tree.add_key_word_from_file("key_words/keywords.txt").unwrap();
tree.build();
let matches = tree.query("回民吃猪肉".as_bytes().as_ref());
assert_eq!(matches[0], "回民".as_bytes().as_ref());
assert_eq!(matches[1], "回民吃猪肉".as_bytes().as_ref());