This commit is contained in:
Matthieu Jolimaitre 2024-10-25 19:20:11 +02:00
commit b130df0391
16 changed files with 339925 additions and 0 deletions

30
src/dictionnary.rs Normal file
View 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
}