Skip to main content

Pattern

Struct Pattern 

Source
pub struct Pattern {
    pub part_of_speech: Vec<String>,
    pub base_forms: Vec<String>,
    pub after: Option<Box<Pattern>>,
}
Expand description

A pattern a morpheme of a bunsetsu matches or not: a prefix of its part-of-speech levels, and optionally its base form and the morpheme before it.

CaboCha matches a prefix of the whole feature string; a pattern states the same thing over the columns of a Schema, so it holds no column number. Every condition has to hold. The pattern without a condition (Pattern::default) matches every morpheme.

§Examples

use lindera_dependency::lattice::LatticeMorpheme;
use lindera_dependency::{Pattern, Schema};

let schema = Schema::ipadic();
let bunsetsu = [
    LatticeMorpheme::new("利用", "名詞,サ変接続,*,*,*,*,利用,リヨウ,リヨー"),
    LatticeMorpheme::new("し", "動詞,自立,*,*,サ変・スル,連用形,する,シ,シ"),
];

// する after a verbal noun.
let pattern = Pattern::new(&["動詞", "自立"])
    .with_base_forms(&["する"])
    .after(Pattern::new(&["名詞", "サ変接続"]));
assert!(pattern.matches(&schema, &bunsetsu, 1));
assert!(!pattern.matches(&schema, &bunsetsu, 0));

Fields§

§part_of_speech: Vec<String>

The first part-of-speech levels the morpheme has to have, from the coarsest: 動詞, 非自立. Empty for any part of speech.

§base_forms: Vec<String>

The base forms the morpheme may have. Empty for any base form.

§after: Option<Box<Pattern>>

What the morpheme before it in the bunsetsu has to match. With it, the first morpheme of a bunsetsu never matches.

Implementations§

Source§

impl Pattern

Source

pub fn new<S: AsRef<str>>(part_of_speech: &[S]) -> Self

Makes a pattern for a part of speech.

§Arguments
  • part_of_speech - The first part-of-speech levels, from the coarsest.
§Returns

The pattern, without a condition on the base form or on the morpheme before.

Source

pub fn with_base_forms<S: AsRef<str>>(self, base_forms: &[S]) -> Self

Limits the pattern to some base forms.

§Arguments
  • base_forms - The base forms the morpheme may have.
§Returns

The pattern with the condition.

Source

pub fn after(self, before: Pattern) -> Self

Limits the pattern to a morpheme that follows another one in its bunsetsu.

§Arguments
  • before - What the morpheme before has to match; Pattern::default for any morpheme.
§Returns

The pattern with the condition.

Source

pub fn matches<M: Morpheme>( &self, schema: &Schema, bunsetsu: &[M], index: usize, ) -> bool

Whether a morpheme of a bunsetsu matches the pattern.

A column the morpheme does not have matches nothing, and neither does a base form when the schema has no column for it.

§Arguments
  • schema - The schema of the dictionary of the morphemes.
  • bunsetsu - The morphemes of the bunsetsu.
  • index - The index of the morpheme in the bunsetsu.
§Returns

Whether the morpheme matches; false for an index outside the bunsetsu.

Trait Implementations§

Source§

impl Clone for Pattern

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 Pattern

Source§

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

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

impl Default for Pattern

Source§

fn default() -> Self

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

impl Eq for Pattern

Source§

impl PartialEq for Pattern

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 Pattern

Auto Trait Implementations§

§

impl Forget for Pattern

§

impl Freeze for Pattern

§

impl Move for Pattern

§

impl RefUnwindSafe for Pattern

§

impl Send for Pattern
where RawVecInner: Send, BoxRaw<Pattern>: Send,

§

impl Sync for Pattern
where RawVecInner: Sync, BoxRaw<Pattern>: Sync,

§

impl Unpin for Pattern
where *const u8 is !null: Unpin, Box<Pattern>: Unpin,

§

impl UnsafeUnpin for Pattern

§

impl UnwindSafe for Pattern
where RawVecInner: UnwindSafe, BoxRaw<Pattern>: 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.