extern crate cmudict;
use std::path::Path;
use cmudict::Cmudict;
pub use cmudict::Result;
pub fn rhymes(left: &str, right: &str) -> Result<Option<bool>> {
let r = Rhyme::new()?;
Ok(r.rhymes(left, right))
}
pub struct Rhyme(cmudict::Cmudict);
impl Rhyme {
pub fn new() -> Result<Rhyme> {
Ok(Rhyme(Cmudict::download()?))
}
pub fn from_path<P: AsRef<Path>>(p: P) -> Result<Rhyme> {
Ok(Rhyme(Cmudict::new(p)?))
}
pub fn rhymes(&self, left: &str, right: &str) -> Option<bool> {
let left = if let Some(left) = self.0.get(&left) {
left
} else {
return None;
};
let right = if let Some(right) = self.0.get(&right) {
right
} else {
return None;
};
Some(cmudict::rhymes(&left, &right))
}
}