Skip to main content

Normalization

Struct Normalization 

Source
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

Source

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.

Source

pub fn is_empty(&self) -> bool

Whether the table has no rule, and changes nothing.

§Returns

Whether it is empty.

Source

pub fn rules(&self) -> impl Iterator<Item = (&str, &str)>

The rules of the table: what is replaced, and by what, sorted by the bytes of what is replaced.

§Returns

The rules.

Source

pub fn apply<'a>(&self, surface: &'a str) -> Cow<'a, str>

Normalizes a surface.

§Arguments
  • surface - The surface.
§Returns

The surface with the rules applied; the surface itself, borrowed, when no rule matches in it.

Trait Implementations§

Source§

impl Clone for Normalization

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Normalization

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Normalization

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Normalization

Source§

impl PartialEq for Normalization

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Normalization

Auto Trait Implementations§

§

impl Forget for Normalization

§

impl Freeze for Normalization

§

impl Move for Normalization

§

impl RefUnwindSafe for Normalization

§

impl Send for Normalization
where RawVecInner: Send,

§

impl Sync for Normalization
where RawVecInner: Sync,

§

impl Unpin for Normalization
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Normalization

§

impl UnwindSafe for Normalization
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.