1use crate::error::*;
2use crate::Adjective::{Long, Possessive, Short};
3use crate::Animacy::{Animate, Inanimate};
4use crate::Case::*;
5use crate::ComparativeDegree::{Comparative, Superlative};
6use crate::Gender::{Feminine, Masculine, Neuter};
7use crate::Mood::{Gerunds, Imperative, Indicative, Infinitive, Participle};
8use crate::Other::{
9 Abbreviation, Awkward, CommonForm, Distorted, FamilyName, Geo, Informal, Obscene, Obsolete,
10 Parenthesis, Patronymic, Predicative, ProperNoun, Rare,
11};
12use crate::PerfectiveAspect::{Imperfective, Perfective};
13use crate::Person::{First, Second, Third};
14use crate::Plurality::{Plural, Singular};
15use crate::Tense::{Inpresent, Past, Present};
16use crate::Transitivity::{Intransitive, Transitive};
17use crate::Voice::{Active, Passive};
18use std::fmt;
19use std::str::FromStr;
20
21#[derive(Debug)]
22pub struct Grammem {
24 pub part_of_speech: PartOfSpeech,
26 pub facts: Vec<Fact>,
28 pub facts_raw: Vec<String>,
30}
31
32#[derive(Debug, PartialEq)]
34pub enum PartOfSpeech {
35 Adjective,
37 Adverb,
39 AdverbPronominal,
41 AdjectiveNumeral,
43 AdjectivePronoun,
45 Composite,
47 Conjunction,
49 Interjection,
51 Numeral,
53 Particle,
55 Preposition,
57 Noun,
59 AdjectiveNoun,
61 Verb,
63}
64impl FromStr for PartOfSpeech {
65 type Err = crate::AppError;
66 fn from_str(input: &str) -> Result<PartOfSpeech, Self::Err> {
67 match input {
68 "A" => Ok(PartOfSpeech::Adjective),
69 "ADV" => Ok(PartOfSpeech::Adverb),
70 "ADVPRO" => Ok(PartOfSpeech::AdverbPronominal),
71 "ANUM" => Ok(PartOfSpeech::AdjectiveNumeral),
72 "APRO" => Ok(PartOfSpeech::AdjectivePronoun),
73 "COM" => Ok(PartOfSpeech::Composite),
74 "CONJ" => Ok(PartOfSpeech::Conjunction),
75 "INTJ" => Ok(PartOfSpeech::Interjection),
76 "NUM" => Ok(PartOfSpeech::Numeral),
77 "PART" => Ok(PartOfSpeech::Particle),
78 "PR" => Ok(PartOfSpeech::Preposition),
79 "S" => Ok(PartOfSpeech::Noun),
80 "SPRO" => Ok(PartOfSpeech::AdjectiveNoun),
81 "V" => Ok(PartOfSpeech::Verb),
82 _ => Err(AppError::PartOfSpeechError("Failed to get Part of Speech.")),
83 }
84 }
85}
86impl fmt::Display for PartOfSpeech {
87 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
88 write!(f, "{:?}", self)
89 }
90}
91
92#[derive(Debug, PartialEq)]
94pub enum Fact {
95 Case(Case),
97 Tense(Tense),
99 Plurality(Plurality),
101 Mood(Mood),
103 Adjective(Adjective),
105 ComparativeDegree(ComparativeDegree),
107 Person(Person),
109 Gender(Gender),
111 PerfectiveAspect(PerfectiveAspect),
113 Voice(Voice),
115 Animacy(Animacy),
117 Transitivity(Transitivity),
119 Other(Other),
121}
122impl fmt::Display for Fact {
123 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124 write!(f, "{:?}", self)
125 }
126}
127
128#[derive(Debug, PartialEq)]
130pub enum Case {
131 Nominative,
133 Genitive,
135 Dative,
137 Accusative,
139 Instrumental,
141 Prepositional,
143 Partitive,
145 Locative,
147 Vocative,
149}
150
151#[derive(Debug, PartialEq)]
153pub enum Tense {
154 Present,
156 Inpresent,
158 Past,
160}
161
162#[derive(Debug, PartialEq)]
164pub enum Plurality {
165 Plural,
167 Singular,
169}
170
171#[derive(Debug, PartialEq)]
173pub enum Mood {
174 Gerunds,
176 Infinitive,
178 Participle,
180 Indicative,
182 Imperative,
184}
185
186#[derive(Debug, PartialEq)]
188pub enum Adjective {
189 Short,
191 Long,
193 Possessive,
195}
196
197#[derive(Debug, PartialEq)]
199pub enum ComparativeDegree {
200 Superlative,
202 Comparative,
204}
205
206#[derive(Debug, PartialEq)]
208pub enum Person {
209 First,
211 Second,
213 Third,
215}
216
217#[derive(Debug, PartialEq)]
219pub enum Gender {
220 Masculine,
222 Feminine,
224 Neuter,
226}
227
228#[derive(Debug, PartialEq)]
230pub enum PerfectiveAspect {
231 Perfective,
233 Imperfective,
235}
236
237#[derive(Debug, PartialEq)]
239pub enum Voice {
240 Passive,
242 Active,
244}
245
246#[derive(Debug, PartialEq)]
248pub enum Animacy {
249 Animate,
251 Inanimate,
253}
254
255#[derive(Debug, PartialEq)]
257pub enum Transitivity {
258 Transitive,
260 Intransitive,
262}
263
264#[derive(Debug, PartialEq)]
266pub enum Other {
267 Parenthesis,
269 Geo,
271 Awkward,
273 ProperNoun,
275 Distorted,
277 CommonForm,
279 Obscene,
281 Patronymic,
283 Predicative,
285 Informal,
287 Rare,
289 Abbreviation,
291 Obsolete,
293 FamilyName,
295}
296
297impl FromStr for Fact {
298 type Err = crate::AppError;
299 fn from_str(input: &str) -> Result<Fact, Self::Err> {
300 match input {
301 "nom" => Ok(Fact::Case(Nominative)),
302 "gen" => Ok(Fact::Case(Genitive)),
303 "dat" => Ok(Fact::Case(Dative)),
304 "acc" => Ok(Fact::Case(Accusative)),
305 "ins" => Ok(Fact::Case(Instrumental)),
306 "abl" => Ok(Fact::Case(Prepositional)),
307 "part" => Ok(Fact::Case(Partitive)),
308 "loc" => Ok(Fact::Case(Locative)),
309 "voc" => Ok(Fact::Case(Vocative)),
310 "praes" => Ok(Fact::Tense(Present)),
311 "inpraes" => Ok(Fact::Tense(Inpresent)),
312 "praet" => Ok(Fact::Tense(Past)),
313 "sg" => Ok(Fact::Plurality(Singular)),
314 "pl" => Ok(Fact::Plurality(Plural)),
315 "ger" => Ok(Fact::Mood(Gerunds)),
316 "inf" => Ok(Fact::Mood(Infinitive)),
317 "partcp" => Ok(Fact::Mood(Participle)),
318 "indic" => Ok(Fact::Mood(Indicative)),
319 "imper" => Ok(Fact::Mood(Imperative)),
320 "brev" => Ok(Fact::Adjective(Short)),
321 "plen" => Ok(Fact::Adjective(Long)),
322 "poss" => Ok(Fact::Adjective(Possessive)),
323 "supr" => Ok(Fact::ComparativeDegree(Superlative)),
324 "comp" => Ok(Fact::ComparativeDegree(Comparative)),
325 "1p" => Ok(Fact::Person(First)),
326 "2p" => Ok(Fact::Person(Second)),
327 "3p" => Ok(Fact::Person(Third)),
328 "m" => Ok(Fact::Gender(Masculine)),
329 "f" => Ok(Fact::Gender(Feminine)),
330 "n" => Ok(Fact::Gender(Neuter)),
331 "pf" => Ok(Fact::PerfectiveAspect(Perfective)),
332 "ipf" => Ok(Fact::PerfectiveAspect(Imperfective)),
333 "act" => Ok(Fact::Voice(Active)),
334 "pass" => Ok(Fact::Voice(Passive)),
335 "anim" => Ok(Fact::Animacy(Animate)),
336 "inan" => Ok(Fact::Animacy(Inanimate)),
337 "tran" => Ok(Fact::Transitivity(Transitive)),
338 "intr" => Ok(Fact::Transitivity(Intransitive)),
339 "parenth" => Ok(Fact::Other(Parenthesis)),
340 "geo" => Ok(Fact::Other(Geo)),
341 "awkw" => Ok(Fact::Other(Awkward)),
342 "persn" => Ok(Fact::Other(ProperNoun)),
343 "dist" => Ok(Fact::Other(Distorted)),
344 "mf" => Ok(Fact::Other(CommonForm)),
345 "obsc" => Ok(Fact::Other(Obscene)),
346 "patrn" => Ok(Fact::Other(Patronymic)),
347 "praed" => Ok(Fact::Other(Predicative)),
348 "inform" => Ok(Fact::Other(Informal)),
349 "rare" => Ok(Fact::Other(Rare)),
350 "abbr" => Ok(Fact::Other(Abbreviation)),
351 "obsol" => Ok(Fact::Other(Obsolete)),
352 "famn" => Ok(Fact::Other(FamilyName)),
353 _ => Err(AppError::GrammemError("Failed to get Grammem.")),
355 }
356 }
357}