-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
585 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::pattern::Pattern; | ||
use uuid::Uuid; | ||
|
||
pub struct PatternRegistry { | ||
patterns: Vec<Pattern>, | ||
} | ||
|
||
impl PatternRegistry { | ||
pub const fn new() -> PatternRegistry { | ||
PatternRegistry { patterns: Vec::new() } | ||
} | ||
|
||
pub fn find_pattern(&mut self, str_text: &Vec<String>, i_text: &Vec<u64>, sample: String) -> &Pattern { | ||
let mut idx: i32 = -1; | ||
let mut mtc = 0; | ||
for i in 0..self.patterns.len() { | ||
mtc = self.patterns[i].match_text(&i_text); | ||
if mtc == -1 || mtc > self.patterns[i].fluct { | ||
continue; | ||
} | ||
idx = i as i32; | ||
break; | ||
} | ||
|
||
if idx == -1 { | ||
let pattern = Pattern::new(Uuid::new_v4().to_string(), &i_text, &str_text, sample); | ||
self.patterns.push(pattern); | ||
idx = (self.patterns.len() - 1) as i32; | ||
} else if mtc != 0 { | ||
self.patterns[idx as usize].adjust_pattern(&i_text); | ||
} | ||
return &self.patterns[idx as usize]; | ||
} | ||
|
||
pub fn to_string(&self) -> String { | ||
let mut s = String::new(); | ||
for i in 0..self.patterns.len() { | ||
s += self.patterns[i].to_string().as_str(); | ||
s += "\n"; | ||
} | ||
return s | ||
} | ||
} | ||
|
||
pub static mut REGISTRY: PatternRegistry = PatternRegistry::new(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use regex::{Regex, CaptureMatches, Match}; | ||
|
||
/*pub fn tokenize(re: &Regex, text: &str) -> CaptureMatches { | ||
return re.captures_iter(text); | ||
}*/ | ||
|
||
pub struct Tokenizer<'a> { | ||
text: String, | ||
pos: usize, | ||
re: Regex, | ||
iter: Option<CaptureMatches<'a, 'a>> | ||
} | ||
|
||
impl Tokenizer<'_> { | ||
pub fn new<'a>(text: &'a str) -> Tokenizer<'a> { | ||
let mut res = Tokenizer { | ||
text: text.to_string(), | ||
pos: 0, | ||
re: Regex::new(r"([\p{L}_]+|[\d.]+|[^\p{L}_\d.]+)\s*").unwrap(), | ||
iter: None | ||
}; | ||
res | ||
} | ||
} | ||
|
||
impl Iterator for Tokenizer<'_> { | ||
type Item = String; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
None | ||
/*let cap: Option<Match> = None; | ||
if let Some(c) = cap { | ||
self.pos += c.get(0).unwrap().end(); | ||
Some(c.get(0).unwrap().as_str().to_string()) | ||
} else { | ||
None | ||
}*/ | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_tokenizer() { | ||
let text = "Hello, world! 123"; | ||
let mut tokenizer = Tokenizer::new(text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.