Skip to content

Commit

Permalink
cut a useless step when reading messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Inspirateur committed Jan 21, 2023
1 parent b785f00 commit 5ddc9c2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

8 changes: 3 additions & 5 deletions src/idiom/idiom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::hash::Hash;
use itertools::Itertools;
use bimap::BiMap;
use super::top_freqs::TopFreqs;
use super::text_utils::counts;
const PLACE_VOC_LEN: usize = 500;
const PERSON_VOC_LEN: usize = 200;

Expand All @@ -27,8 +26,7 @@ impl<P: Hash+Eq, U: Hash+Eq> Idioms<P, U> {
pub fn update(&mut self, place: P, person: U, tokens: Vec<String>) {
let place_voc = self.places.entry(place).or_insert(TopFreqs::new());
let user_voc = self.people.entry(person).or_insert(TopFreqs::new());
let tokens = counts(tokens);
for (token, value) in tokens {
for token in tokens {
let idx = match self.tokens.get_by_left(&token) {
Some(v) => *v,
None => {
Expand All @@ -37,8 +35,8 @@ impl<P: Hash+Eq, U: Hash+Eq> Idioms<P, U> {
v
}
};
place_voc.add(idx, value);
let inctx_value = (-place_voc.get(&idx)).exp()*50.;
place_voc.add(idx, 1.);
let inctx_value = (-place_voc.get(&idx)).exp()*20.;
user_voc.add(idx, inctx_value);
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/idiom/text_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
Expand Down Expand Up @@ -31,11 +30,3 @@ pub fn tokenize(text: String) -> Vec<String> {
.map(|token| smart_lower(trim(token.as_str())))
.collect_vec()
}

pub(crate) fn counts(tokens: Vec<String>) -> Vec<(String, f32)> {
let mut counts: HashMap<String, usize> = HashMap::new();
for token in tokens {
*counts.entry(token.as_str().to_string()).or_default() += 1;
}
counts.into_iter().map(|(k, v)| (k, v as f32)).collect()
}

0 comments on commit 5ddc9c2

Please sign in to comment.