-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and spell check index start
- Loading branch information
Showing
14 changed files
with
282 additions
and
118 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
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,8 @@ | ||
web: | ||
cargo run --release --bin server $(index_name) | ||
|
||
cli: | ||
cargo run --release --bin search $(index_name) ${action} | ||
|
||
test: | ||
cargo test --release |
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
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,42 @@ | ||
use regex::Regex; | ||
use rust_stemmers::{Algorithm, Stemmer}; | ||
|
||
pub struct Preprocessor { | ||
stemmer: Stemmer, | ||
regex: Regex, | ||
} | ||
|
||
impl Preprocessor { | ||
pub fn new() -> Preprocessor { | ||
Preprocessor { | ||
stemmer: Stemmer::create(Algorithm::English), | ||
regex: Regex::new(r"[^a-zA-Z0-9\s]+").expect("error while building regex"), | ||
} | ||
} | ||
|
||
pub fn tokenize_and_stem(&self, text: &str) -> Vec<String> { | ||
self.regex | ||
.replace_all(text, " ") | ||
.split_whitespace() | ||
.map(|t| t.to_lowercase()) | ||
.map(|t| self.stemmer.stem(&t).to_string()) | ||
.collect() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_tokenize_and_stem() { | ||
let preprocessor = Preprocessor::new(); | ||
|
||
let text1 = "The quick brown, fox jumps over the lazy dog!!!"; | ||
let result1 = preprocessor.tokenize_and_stem(text1); | ||
assert_eq!( | ||
result1, | ||
vec!["the", "quick", "brown", "fox", "jump", "over", "the", "lazi", "dog"] | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.