Skip to content
Snippets Groups Projects
Commit cc083ec2 authored by Phil Höfer's avatar Phil Höfer
Browse files

Start Implementing New Blocklist

parent cffc3822
No related branches found
No related tags found
No related merge requests found
Pipeline #10061 passed
use std::{collections::HashMap, fs::File};
use std::{collections::HashMap, fs::{self, File}};
use csv::ReaderBuilder;
......@@ -46,13 +46,26 @@ impl Predictor for MarkovChainPredictor {
}
fn update_from_query(&mut self, query: &str) -> Result<(), Box<dyn std::error::Error>> {
let blocklist: Vec<&str> = match self.configuration.get("blocked_words") {
let mut raw_list = String::new();
let blocklist: Vec<&str> = match self.configuration.get("blocklist") {
Some(list) => {
list.split_whitespace().collect()
match fs::read_to_string(list) {
Ok(l) => {
raw_list = l.clone();
raw_list.lines().collect()
},
_ => Vec::new()
}
},
_ => Vec::new()
};
};
for word in blocklist.clone() {
if query.contains(word) {
return Ok(());
}
}
//println!("blocklist:{:?}",self.configuration);
......
use std::{collections::HashMap, f32::consts::E, fs::File};
use std::{collections::HashMap, f32::consts::E, fs::{self, File}};
use crate::importers::Importer;
......@@ -45,13 +45,26 @@ impl Predictor for SetPredictor {
}
fn update_from_query(&mut self, query: &str) -> Result<(), Box<dyn std::error::Error>> {
let blocklist: Vec<&str> = match self.configuration.get("blocked_words") {
let mut raw_list = String::new();
let blocklist: Vec<&str> = match self.configuration.get("blocklist") {
Some(list) => {
list.split_whitespace().collect()
match fs::read_to_string(list) {
Ok(l) => {
raw_list = l.clone();
raw_list.lines().collect()
},
_ => Vec::new()
}
},
_ => Vec::new()
};
};
for word in blocklist.clone() {
if query.contains(word) {
return Ok(());
}
}
//println!("blocklist:{:?}",self.configuration);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment