Skip to content

Commit de6dc72

Browse files
committed
Expand stop word list to cover more stop words.
1 parent ffd459e commit de6dc72

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/lexer.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use rust_stemmers::{Algorithm, Stemmer};
22

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+
];
411

512
#[derive(Debug)]
613
pub struct Lexer<'a> {
@@ -57,15 +64,12 @@ impl<'a> Lexer<'a> {
5764
if self.content[0].is_alphabetic() {
5865
let result = self.chop_while(|x| x.is_alphanumeric());
5966
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()) {
6370
return None;
6471
}
65-
66-
// Stemming
67-
let stemmed_token = stemmer.stem(&token).into_owned().to_uppercase();
68-
return Some(stemmed_token);
72+
return Some(stemmed);
6973
}
7074

7175
let token = self.chop(1);

0 commit comments

Comments
 (0)