pub struct Schema {Show 13 fields
pub part_of_speech: Range<usize>,
pub conjugation_type: Option<usize>,
pub conjugation_form: Option<usize>,
pub base_form: Option<usize>,
pub function_words: Vec<Pattern>,
pub not_heads: Vec<Pattern>,
pub particles: Vec<Pattern>,
pub lexicalized: Vec<Pattern>,
pub symbols: Symbols,
pub normalization: Normalization,
pub head_rule: HeadRule,
pub head_fallback: HeadFallback,
pub sentence_split: SentenceSplit,
}Expand description
What is known about a dictionary: which feature columns hold the part of speech, the conjugation and the base form, which morphemes are function words, which are not heads, and which are symbols.
Columns are counted from 0, as Morpheme::feature
does.
Fields§
§part_of_speech: Range<usize>The columns of the part of speech, from the coarsest level to the finest.
conjugation_type: Option<usize>The column of the conjugation type, when the dictionary has one.
conjugation_form: Option<usize>The column of the conjugation form, when the dictionary has one.
base_form: Option<usize>The column of the base form, when the dictionary has one.
function_words: Vec<Pattern>The function words: a morpheme that matches one of these patterns.
not_heads: Vec<Pattern>What is neither a function word nor a head, besides the symbols: a morpheme that matches one of these patterns.
particles: Vec<Pattern>The particles: a morpheme that matches one of these patterns. The parser names the particles of a bunsetsu in its features.
lexicalized: Vec<Pattern>The function words that tell by their surface how a bunsetsu modifies another: a morpheme that matches one of these patterns. For a bunsetsu that ends in any other word, the parser takes the conjugation form or the part of speech in its place.
symbols: SymbolsHow symbols, punctuation and brackets are recognized.
normalization: NormalizationWhat a surface is replaced by before it becomes a feature or is matched as a mark: empty for the schemas of this crate, the table of CaboCha for a model converted from CaboCha.
head_rule: HeadRuleHow the head word and the function word of a bunsetsu are found.
head_fallback: HeadFallbackThe head word of a bunsetsu in which the rule finds none.
sentence_split: SentenceSplitWhether a chunker cuts a text into sentences before it gives it to its model.
Implementations§
Source§impl Schema
impl Schema
Sourcepub const DICTIONARIES: [&'static str; 4]
pub const DICTIONARIES: [&'static str; 4]
The names of the dictionaries Schema::for_dictionary has a schema
for.
Sourcepub fn ipadic() -> Self
pub fn ipadic() -> Self
The schema of IPADIC.
The columns are four levels of part of speech, then the conjugation type, the conjugation form and the base form.
The function words are those of CaboCha for IPA (助詞, 助動詞, 動詞,非自立, 動詞,接尾, 形容詞,非自立, 形容詞,接尾), and する and できる (動詞,自立): in 利用 / し / た the head is 利用. At the start of a bunsetsu する is still the head, since the head starts there and only a head moves it.
Besides the symbols, these are not heads: 名詞,非自立 (こと, の, よう); the suffixes 的 (名詞,接尾,形容動詞語幹) and さ (名詞,接尾,特殊), so that in 基本 / 的 / に the head is 基本; and a 動詞,自立 right after a 助詞, which is part of a compound function word (こと / に / なっ / た, かも / しれ / ない).
With CaboCha’s rule alone the head is the content head of UD Japanese-GSD in 85% of the bunsetsu; with these additions, in 97%. The README of the crate has the measurement.
A symbol is a morpheme of the part of speech 記号, or one whose
surface is made of symbol characters only: IPADIC has no half-width
symbols, and gives , as 名詞,サ変接続.
The particles are 助詞, and the function words taken by their surface are 助詞, 副詞, 連体詞 and 接続詞, as in CaboCha.
§Returns
The schema.
Sourcepub fn unidic() -> Self
pub fn unidic() -> Self
The schema of UniDic: of unidic (unidic-mecab 2.1.2), unidic-cwj
and unidic-csj, whose first columns are the same.
The columns are 品詞大分類, 中分類, 小分類, 細分類, 活用型, 活用形, 語彙素読み and 語彙素; the base form is the 語彙素, so that of こと is 事.
The function words are the ones of the pattern CaboCha has for UniDic (a particle, an auxiliary, and a suffix that is not nominal), and a verb or an adjective that is 非自立可能. What is not a head was measured on UD Japanese-GSD, as for IPADIC:
- a verb right after に, と or を (に / よっ / て, と / し / て),
- a 助動詞語幹 (よう, そう, みたい),
- a formal noun (こと, ため, もの, 際, うえ, ところ) right after a verb, an auxiliary or an adjective,
- a nominal suffix right after an adjective (大き / さ).
UniDic tags a letter of the Latin alphabet 記号,文字, and it is a symbol here as any 記号 is.
§Returns
The schema.
§Examples
use lindera_dependency::Schema;
use lindera_dependency::lattice::LatticeMorpheme;
let schema = Schema::unidic();
// 利用 / する / こと / が
let bunsetsu = [
LatticeMorpheme::new("利用", "名詞,普通名詞,サ変可能,*,*,*,リヨウ,利用"),
LatticeMorpheme::new("する", "動詞,非自立可能,*,*,サ行変格,連体形-一般,スル,為る"),
LatticeMorpheme::new("こと", "名詞,普通名詞,一般,*,*,*,コト,事"),
LatticeMorpheme::new("が", "助詞,格助詞,*,*,*,*,ガ,が"),
];
// The head word is 利用 and the function word が: する is 非自立可能,
// and こと is a formal noun after a verb.
assert_eq!(schema.positions(&bunsetsu), Some((0, 3)));Sourcepub fn for_dictionary(dictionary: &str) -> Option<Self>
pub fn for_dictionary(dictionary: &str) -> Option<Self>
The schema of a dictionary of Lindera, by the name of the dictionary.
§Arguments
dictionary- The name of the dictionary, as its metadata has it:ipadic,unidic,unidic-cwjorunidic-csj.
§Returns
The schema, or None for a dictionary this crate has no schema for.
§Examples
use lindera_dependency::Schema;
assert_eq!(Schema::for_dictionary("ipadic"), Some(Schema::ipadic()));
// The three UniDic dictionaries have one schema.
assert_eq!(Schema::for_dictionary("unidic-cwj"), Some(Schema::unidic()));
assert_eq!(Schema::for_dictionary("ko-dic"), None);
assert_eq!(
Schema::DICTIONARIES,
["ipadic", "unidic", "unidic-cwj", "unidic-csj"]
);Sourcepub fn positions<M: Morpheme>(&self, bunsetsu: &[M]) -> Option<(usize, usize)>
pub fn positions<M: Morpheme>(&self, bunsetsu: &[M]) -> Option<(usize, usize)>
The positions of the head word and of the function word of a
bunsetsu: what Bunsetsu::positions
holds.
See the module documentation for the rule. A bunsetsu
without a function word has the function word at its head. A
bunsetsu in which the rule finds no head word has the one
Schema::head_fallback names, and both at its first morpheme when
it is of symbols only. A space is neither of the two, unless the
bunsetsu is of spaces alone.
§Arguments
bunsetsu- The morphemes of the bunsetsu.
§Returns
The positions of the head word and of the function word, counted
from the first morpheme of the bunsetsu; None for no morpheme.
Sourcepub fn sentence_starts<M: Morpheme>(&self, words: &[M]) -> Vec<usize>
pub fn sentence_starts<M: Morpheme>(&self, words: &[M]) -> Vec<usize>
Where the sentences of a text start, for a chunker: the words at which it cuts the text, so that its model is given one sentence at a time.
With SentenceSplit::AfterEnds, a sentence end
(is_sentence_end) takes the
ends and the closing brackets that follow it, and the word after
them starts a sentence: 読んだ / 。 / 面白かっ / た is cut before
面白かっ. Two cases are left whole, where the word after the end
belongs to the bunsetsu of a quotation:
- a function word after a closing bracket, as と in …。 / 」 / と / 言っ / た;
- the particle of a quotation, と or って, also without a bracket, as in …な / の / か / ? / と / 、.
Another function word without a closing bracket starts a sentence as any word does: …。 / だ / が, and …。 / で / も, which UniDic gives as two particles.
A sentence end that a dictionary joined with other marks is one too, and its closing bracket counts as one: IPADIC gives 本当 / ?」 / と, and nothing is cut before と.
§Arguments
words- The words of the text: its morphemes without the spaces.
§Returns
The indices of the words that start a sentence, in order, each
larger than 0: the first word starts one in any case and is not
listed. Empty with SentenceSplit::None, and for a text of one
sentence.
Sourcepub fn sentence_ends<M: Morpheme>(&self, morphemes: &[M]) -> Vec<usize>
pub fn sentence_ends<M: Morpheme>(&self, morphemes: &[M]) -> Vec<usize>
Where the sentences of a text end, for a reader of text: what a chunker and a parser are given one at a time.
The models are trained on single sentences. A sentence ends after a
sentence end (is_sentence_end)
that is outside brackets, and takes the ends, the closing brackets
and the spaces that follow it: a quotation is one sentence with the
sentence around it. A word of marks that a dictionary joined is read
one mark at a time (marks), and an
opening bracket that nothing in the text closes is no bracket.
The token filter japanese_dependency and the layer of text of
lindera dependency parse cut their text with it, so that a text is
analyzed the same way through either. Schema::sentence_starts is
another cut, the one a chunker makes inside what it is given: it also
cuts inside brackets, where a bunsetsu starts after a sentence end
all the same.
§Arguments
morphemes- The morphemes of the text, with its spaces.
§Returns
The end of each sentence, as the index after its last morpheme; the last one is the number of morphemes. Nothing for no morpheme.
§Examples
use lindera_dependency::Schema;
use lindera_dependency::lattice::LatticeMorpheme;
let noun = |surface| LatticeMorpheme::new(surface, "名詞,一般,*,*,*,*,*,*,*");
let mark = |surface, kind| LatticeMorpheme::new(surface, format!("記号,{kind},*,*,*,*,*,*,*"));
// 本 。 「 本 。 」 本: the second 。 is inside the brackets.
let text = [
noun("本"),
mark("。", "句点"),
mark("「", "括弧開"),
noun("本"),
mark("。", "句点"),
mark("」", "括弧閉"),
noun("本"),
];
assert_eq!(Schema::ipadic().sentence_ends(&text), [2, 7]);Sourcepub fn surface_of<'a, M: Morpheme>(&self, morpheme: &'a M) -> Cow<'a, str>
pub fn surface_of<'a, M: Morpheme>(&self, morpheme: &'a M) -> Cow<'a, str>
The surface of a morpheme as the chunker and the parser use it:
with Schema::normalization applied.
§Arguments
morpheme- The morpheme.
§Returns
The normalized surface; the surface itself when the schema does not normalize, or when no rule matches in it.
Sourcepub fn is_particle<M: Morpheme>(&self, bunsetsu: &[M], index: usize) -> bool
pub fn is_particle<M: Morpheme>(&self, bunsetsu: &[M], index: usize) -> bool
Whether a morpheme of a bunsetsu is a particle: it matches one of
Schema::particles.
§Arguments
bunsetsu- The morphemes of the bunsetsu.index- The index of the morpheme in the bunsetsu.
§Returns
Whether it is a particle; false for an index past the bunsetsu.
Sourcepub fn is_lexicalized<M: Morpheme>(&self, bunsetsu: &[M], index: usize) -> bool
pub fn is_lexicalized<M: Morpheme>(&self, bunsetsu: &[M], index: usize) -> bool
Whether a morpheme of a bunsetsu tells by its surface how the
bunsetsu modifies another: it matches one of
Schema::lexicalized.
§Arguments
bunsetsu- The morphemes of the bunsetsu.index- The index of the morpheme in the bunsetsu.
§Returns
Whether it is such a word; false for an index past the bunsetsu.
Sourcepub fn is_open_bracket<M: Morpheme>(&self, morpheme: &M) -> bool
pub fn is_open_bracket<M: Morpheme>(&self, morpheme: &M) -> bool
Sourcepub fn is_close_bracket<M: Morpheme>(&self, morpheme: &M) -> bool
pub fn is_close_bracket<M: Morpheme>(&self, morpheme: &M) -> bool
Sourcepub fn part_of_speech_of<M: Morpheme>(&self, morpheme: &M) -> String
pub fn part_of_speech_of<M: Morpheme>(&self, morpheme: &M) -> String
Sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
The number of feature columns the schema reads.
§Returns
One more than the largest index among the columns of the part of speech, of the conjugation and of the base form: a morpheme of the dictionary has at least this many columns.
Sourcepub fn check<M: Morpheme>(&self, morphemes: &[M]) -> Result<()>
pub fn check<M: Morpheme>(&self, morphemes: &[M]) -> Result<()>
Checks that morphemes can be of the dictionary of the schema.
A morpheme with fewer feature columns than the schema reads comes
from another dictionary, or from a tokenizer that drops columns:
analyzing it would give an answer from columns that are not there.
Morphemes of another dictionary that are wide enough pass; the name
of the dictionary in a model file is for those
(Model::check_dictionary).
§Arguments
morphemes- The morphemes.
§Returns
Ok(()), or Error::Dictionary for the first morpheme that has
fewer columns than Schema::width.