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
impl Pattern
Sourcepub fn with_base_forms<S: AsRef<str>>(self, base_forms: &[S]) -> Self
pub fn with_base_forms<S: AsRef<str>>(self, base_forms: &[S]) -> Self
Sourcepub fn after(self, before: Pattern) -> Self
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::defaultfor any morpheme.
§Returns
The pattern with the condition.
Sourcepub fn matches<M: Morpheme>(
&self,
schema: &Schema,
bunsetsu: &[M],
index: usize,
) -> bool
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.