Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target/
docs.gl/

index.json
index.db
index-big.json
index*

.[dD]S_Store
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
colored = "3.0.0"
rust-stemmers = "1.2.0"
serde = { version = "1.0.219" , features = ["derive"] }
serde_json = "1.0.140"
sqlite = "0.30.3"
Expand Down
8 changes: 7 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use rust_stemmers::{Algorithm, Stemmer};

#[derive(Debug)]
pub struct Lexer<'a> {
// Lifetimes implemented as content is not owned
Expand Down Expand Up @@ -38,6 +40,7 @@ impl<'a> Lexer<'a> {
}

fn next_token(&mut self) -> Option<String> {
let stemmer = Stemmer::create(Algorithm::English);
self.trim_left();

if self.content.len() == 0 {
Expand All @@ -53,7 +56,10 @@ impl<'a> Lexer<'a> {

if self.content[0].is_alphabetic() {
let result = self.chop_while(|x| x.is_alphanumeric());
return Some(result.iter().map(|x| x.to_ascii_uppercase()).collect());
let token = result.iter().collect::<String>();
let stemmed_token = stemmer.stem(&token).into_owned().to_uppercase();
println!("Before: {}, After: {}", token, stemmed_token);
return Some(stemmed_token);
}

// // Ignore single-character unwanted punctuation
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn parse_xml_file(file_path: &Path) -> Result<String, ()> {
})?;
let er = EventReader::new(BufReader::new(file));
let mut content = String::new();

for event in er.into_iter() {
let event = event.map_err(|err| {
let TextPosition {row, column} = err.position();
Expand Down Expand Up @@ -166,7 +167,7 @@ fn fetch_model(index_path: &str) -> Result<InMemoryModel, ()> {

return Ok(model);
}

fn usage(program: &String) {
eprintln!("{}: {program} [SUBCOMMAND] [OPTIONS]", "USAGE".bold().cyan(), program = program.bright_blue());
eprintln!("Subcommands:");
Expand Down Expand Up @@ -195,7 +196,7 @@ fn entry() -> Result<(), ()> {

let subcommand = subcommand.ok_or_else(|| {
usage(&program);
eprintln!("ERROR: no subcommand is provided");
eprintln!("{}: no subcommand is provided", "ERROR".red().bold());
})?;

match subcommand.as_str() {
Expand Down
Loading