pub struct FeatureSet { /* private fields */ }Expand description
The groups of features a model uses.
A feature set is data of a model, as the template of the chunker is: the
features of training and of parsing are made from the same value, and
two sets are compared without a change of code. It is written as the
names of its groups with commas, as in distance,source,target,gap.
A set can also limit the levels of the part of speech its features
take (FeatureSet::with_part_of_speech_levels), written after the
groups as in distance,source,pos-levels=2. Without a limit the
features take every level of the schema.
Implementations§
Source§impl FeatureSet
impl FeatureSet
Sourcepub fn new(groups: &[Group]) -> Result<Self>
pub fn new(groups: &[Group]) -> Result<Self>
Makes a feature set of groups.
§Arguments
groups- The groups, in any order.
§Returns
The set, or Error::Parser for no group or a group given twice.
Sourcepub fn with_part_of_speech_levels(self, levels: usize) -> Result<Self>
pub fn with_part_of_speech_levels(self, levels: usize) -> Result<Self>
Limits the levels of the part of speech the features take.
The features of a morpheme name the levels of its part of speech
(HP0:名詞, HP1:普通名詞), and the feature of a bunsetsu that
ends in a word without a conjugation form is its part of speech,
the levels joined (A:名詞-普通名詞). With a limit, both stop at
that many levels, though the schema has more: the chunker and the
patterns of the schema still read all of them. CaboCha reads two
levels of UniDic in its parser and four in its chunker.
§Arguments
levels- The number of levels, 1 or more.
§Returns
The set with the limit, or Error::Parser for 0.
§Examples
use lindera_dependency::parser::FeatureSet;
let set = FeatureSet::cabocha().with_part_of_speech_levels(2)?;
assert_eq!(set.part_of_speech_levels(), Some(2));
assert_eq!(
set.to_string(),
"distance,source,target,left,right,children,gap,pos-levels=2"
);
assert_eq!(FeatureSet::parse(&set.to_string())?, set);Sourcepub fn part_of_speech_levels(&self) -> Option<usize>
pub fn part_of_speech_levels(&self) -> Option<usize>
The limit of the levels of the part of speech.
§Returns
The number of levels the features take, or None for every level
of the schema.
Sourcepub fn parse(text: &str) -> Result<Self>
pub fn parse(text: &str) -> Result<Self>
Reads a feature set from its text.
§Arguments
text- The names of the groups, separated by commas; spaces around a name are ignored.pos-levels=<number>among them is the limit ofFeatureSet::with_part_of_speech_levels.
§Returns
The set, or Error::Parser for a name that is not a group, no
group, a group given twice, or a limit that is not a number of 1 or
more, or is given twice.
Trait Implementations§
Source§impl Clone for FeatureSet
impl Clone for FeatureSet
Source§impl Debug for FeatureSet
impl Debug for FeatureSet
Source§impl Default for FeatureSet
impl Default for FeatureSet
Source§fn default() -> Self
fn default() -> Self
Every group: the feature set of CaboCha and Group::AfterHead,
which is what a model is trained with unless another set is given.