pub struct Normalization { /* private fields */ }Expand description
A table that replaces parts of a surface before the surface becomes a feature of the chunker or of the parser, or is matched as punctuation or as a bracket.
A rule replaces a string by another one. At each position of a surface the longest rule that matches there is applied; where none matches, one character is kept as it is. The result of a rule is not looked at again. An empty table changes nothing, which is what the schemas of this crate have: they recognize a mark in its full-width and its half-width form instead.
The table is there for models made by another program that normalizes: CaboCha writes the half-width katakana in full width, and the full-width letters, digits and signs in ASCII, before it makes a feature. A model converted from CaboCha carries CaboCha’s table, so that its features are the ones CaboCha makes.
§Examples
use lindera_dependency::schema::Normalization;
let table = Normalization::new(&[("カ", "カ"), ("ガ", "ガ"), ("1", "1")]).unwrap();
// The longest rule first: ガ is ガ, not カ and a mark.
assert_eq!(table.apply("ガカ1番"), "ガカ1番");
assert_eq!(Normalization::default().apply("ガ"), "ガ");Implementations§
Source§impl Normalization
impl Normalization
Sourcepub fn new(rules: &[(&str, &str)]) -> Result<Self>
pub fn new(rules: &[(&str, &str)]) -> Result<Self>
Makes a table.
§Arguments
rules- The rules: what is replaced, and by what. Their order does not matter. A rule given twice with the same result is one rule.
§Returns
The table, or Error::Schema for a rule that replaces an empty
string, or for two rules that replace the same string by different
ones.