use serde::Deserialize;
use super::Inflections;
#[derive(Debug, Clone, Deserialize)]
pub struct Rule {
pub pattern: String,
pub replacement: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Irregular {
pub singular: String,
pub plural: String,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct InflectionConfig {
pub plurals: Vec<Rule>,
pub singulars: Vec<Rule>,
pub irregulars: Vec<Irregular>,
pub uncountables: Vec<String>,
pub acronyms: Vec<String>,
}
impl InflectionConfig {
pub fn from_yaml(yaml: &str) -> Result<Self, serde_norway::Error> {
serde_norway::from_str(yaml)
}
pub fn apply(&self, inflections: &mut Inflections) {
for rule in &self.plurals {
inflections.plural(&rule.pattern, &rule.replacement);
}
for rule in &self.singulars {
inflections.singular(&rule.pattern, &rule.replacement);
}
for irr in &self.irregulars {
inflections.irregular(&irr.singular, &irr.plural);
}
for word in &self.uncountables {
inflections.uncountable(word);
}
for word in &self.acronyms {
inflections.acronym(word);
}
}
}