init
This commit is contained in:
commit
b130df0391
16 changed files with 339925 additions and 0 deletions
30
src/dictionnary.rs
Normal file
30
src/dictionnary.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
|
||||
pub fn load(path: impl AsRef<Path>, width: usize) -> Vec<String> {
|
||||
let content = fs::read_to_string(path).expect("Can read file.");
|
||||
content
|
||||
.lines()
|
||||
.filter(|w| w.len() == width)
|
||||
.map(|l| l.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn francais(width: usize) -> Vec<String> {
|
||||
let raw = include_str!("../data/francais.txt");
|
||||
raw.lines()
|
||||
.filter(|w| w.len() == width)
|
||||
.map(|l| l.to_string())
|
||||
.collect()
|
||||
}
|
||||
pub fn gutenberg(width: usize) -> Vec<String> {
|
||||
let raw = include_str!("../data/gutenberg.txt");
|
||||
let mut res = raw
|
||||
.lines()
|
||||
.filter(|w| w.len() == width)
|
||||
.map(|l| l.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
res.shuffle(&mut thread_rng());
|
||||
res
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue