Created
December 31, 2017 02:22
-
-
Save bhickey/1aea0468b268cf3968f8c6981985ddf8 to your computer and use it in GitHub Desktop.
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
#[derive(Debug, PartialEq)] | |
struct Ngram { | |
tokens: Vec<String>, | |
year: i32, | |
count: i64, | |
docs: i32 | |
} | |
impl FromStr for Ngram { | |
type Err = ParseIntError; | |
fn from_str(s: &str) -> Result<Self, Self::Err> { | |
let mut parts: Vec<String> = s.split_whitespace().map(|s| s.to_string()).collect(); | |
let len = parts.len(); | |
let year = parts[len - 3].parse::<i32>()?; | |
let count = parts[len - 2].parse::<i64>()?; | |
let docs = parts[len - 1].parse::<i32>()?; | |
parts.truncate(len - 3); | |
Ok(Ngram { tokens: parts, year: year, count: count, docs: docs }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment