|
1 | 1 | use rust_stemmers::{Algorithm, Stemmer}; |
2 | 2 |
|
3 | | -const STOP_WORDS: [&str; 4] = ["is", "as", "the", "a"]; |
| 3 | +const STOP_WORDS: &[&str] = &[ |
| 4 | + "A", "AN", "THE", |
| 5 | + "IS", "AS", "ARE", "WAS", "WERE", "BE", "BEEN", "BEING", |
| 6 | + "AND", "OR", "BUT", "NOR", "SO", "YET", |
| 7 | + "IN", "ON", "AT", "TO", "FOR", "OF", "WITH", "BY", "FROM", |
| 8 | + "IT", "ITS", "THIS", "THAT", |
| 9 | + "NOT", "NO", |
| 10 | +]; |
4 | 11 |
|
5 | 12 | #[derive(Debug)] |
6 | 13 | pub struct Lexer<'a> { |
@@ -57,15 +64,12 @@ impl<'a> Lexer<'a> { |
57 | 64 | if self.content[0].is_alphabetic() { |
58 | 65 | let result = self.chop_while(|x| x.is_alphanumeric()); |
59 | 66 | let token = result.iter().collect::<String>(); |
60 | | - |
61 | | - // Remove stop words |
62 | | - if STOP_WORDS.contains(&token.as_str()) { |
| 67 | + |
| 68 | + let stemmed = stemmer.stem(&token).into_owned().to_uppercase(); |
| 69 | + if STOP_WORDS.contains(&stemmed.as_str()) { |
63 | 70 | return None; |
64 | 71 | } |
65 | | - |
66 | | - // Stemming |
67 | | - let stemmed_token = stemmer.stem(&token).into_owned().to_uppercase(); |
68 | | - return Some(stemmed_token); |
| 72 | + return Some(stemmed); |
69 | 73 | } |
70 | 74 |
|
71 | 75 | let token = self.chop(1); |
|
0 commit comments