Fix clippy problems in test data setup

This commit is contained in:
Dirkjan Ochtman 2020-12-07 11:46:42 +01:00
parent 4aaa661328
commit 912e6477e3
1 changed files with 8 additions and 7 deletions

View File

@ -13,33 +13,34 @@ pub fn segmenter() -> Segmenter {
let uni_file = dir.join("unigrams.txt");
let reader = BufReader::new(File::open(&uni_file).unwrap());
let unigrams = reader.lines().enumerate().map(move |(i, ln)| {
let ln = ln.expect(&format!("line error at {:?}:{}", uni_file, i));
let ln = ln.unwrap_or_else(|e| panic!("line error at {:?}:{}: {}", uni_file, i, e));
let split = ln
.find('\t')
.expect(&format!("no tab found in {:?}:{}", uni_file, i));
.unwrap_or_else(|| panic!("no tab found in {:?}:{}", uni_file, i));
let word = ln[..split].into();
let p = usize::from_str(&ln[split + 1..]).expect(&format!("error at {:?}:{}", uni_file, i));
let p = usize::from_str(&ln[split + 1..])
.unwrap_or_else(|e| panic!("error at {:?}:{}: {}", uni_file, i, e));
(word, p as f64)
});
let bi_file = dir.join("bigrams.txt");
let reader = BufReader::new(File::open(&bi_file).unwrap());
let bigrams = reader.lines().enumerate().map(move |(i, ln)| {
let ln = ln.expect(&format!("line error at {:?}:{}", bi_file, i));
let ln = ln.unwrap_or_else(|e| panic!("line error at {:?}:{}: {}", bi_file, i, e));
let word_split = ln
.find(' ')
.expect(&format!("no space found in {:?}:{}", bi_file, i));
.unwrap_or_else(|| panic!("no space found in {:?}:{}", bi_file, i));
let score_split = ln[word_split + 1..]
.find('\t')
.expect(&format!("no tab found in {:?}:{}", bi_file, i))
.unwrap_or_else(|| panic!("no tab found in {:?}:{}", bi_file, i))
+ word_split
+ 1;
let word1 = ln[..word_split].into();
let word2 = ln[word_split + 1..score_split].into();
let p = usize::from_str(&ln[score_split + 1..])
.expect(&format!("error at {:?}:{}", bi_file, i));
.unwrap_or_else(|e| panic!("error at {:?}:{}: {}", bi_file, i, e));
((word1, word2), p as f64)
});