-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use rand::seq::IteratorRandom; | ||
pub enum SamplingMethod { | ||
Top, | ||
Random, | ||
} | ||
|
||
pub struct Corpus { | ||
pub words: Vec<&'static str>, | ||
} | ||
|
||
impl Corpus { | ||
pub fn sample(&self, n: usize, method: SamplingMethod) -> Corpus { | ||
Corpus { | ||
words: match method { | ||
SamplingMethod::Top => self.words.iter().take(n).cloned().collect(), | ||
SamplingMethod::Random => { | ||
let mut rng = rand::thread_rng(); | ||
self.words.iter().cloned().choose_multiple(&mut rng, n) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
pub fn english_200_words() -> Corpus { | ||
Corpus { | ||
words: vec![ | ||
"the", "be", "of", "and", "a", "to", "in", "he", "have", "it", "that", "for", | ||
"they", "I", "with", "as", "not", "on", "she", "at", "by", "this", "we", "you", | ||
"do", "but", "from", "or", "which", "one", "would", "all", "will", "there", "say", | ||
"who", "make", "when", "can", "more", "if", "no", "man", "out", "other", "so", | ||
"what", "time", "up", "go", "about", "than", "into", "could", "state", "only", | ||
"new", "year", "some", "take", "come", "these", "know", "see", "use", "get", | ||
"like", "then", "first", "any", "work", "now", "may", "such", "give", "over", | ||
"think", "most", "even", "find", "day", "also", "after", "way", "many", "must", | ||
"look", "before", "great", "back", "through", "long", "where", "much", "should", | ||
"well", "people", "down", "own", "just", "because", "good", "each", "those", | ||
"feel", "seem", "how", "high", "too", "place", "little", "world", "very", "still", | ||
"nation", "hand", "old", "life", "tell", "write", "become", "here", "show", | ||
"house", "both", "between", "need", "mean", "call", "develop", "under", "last", | ||
"right", "move", "thing", "general", "school", "never", "same", "another", "begin", | ||
"while", "number", "part", "turn", "real", "leave", "might", "want", "point", | ||
"form", "off", "child", "few", "small", "since", "against", "ask", "late", "home", | ||
"interest", "large", "person", "end", "open", "public", "follow", "during", | ||
"present", "without", "again", "hold", "govern", "around", "possible", "head", | ||
"consider", "word", "program", "problem", "however", "lead", "system", "set", | ||
"order", "eye", "plan", "run", "keep", "face", "fact", "group", "play", "stand", | ||
"increase", "early", "course", "change", "help", "line", | ||
], | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Corpus { | ||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(formatter, "{}", self.words.join(" ")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod corpus; | ||
|
||
pub mod action; | ||
pub mod model; | ||
pub mod terminal; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters