1use std::fmt::Display;
2
3use is_macro::Is;
4use serde::{Deserialize, Serialize};
5use strum_macros::{AsRefStr, EnumIter, EnumString};
6
7#[derive(
9 EnumString,
10 Debug,
11 Default,
12 Hash,
13 Eq,
14 PartialEq,
15 Clone,
16 Copy,
17 EnumIter,
18 AsRefStr,
19 Serialize,
20 Deserialize,
21 PartialOrd,
22 Ord,
23 Is,
24)]
25pub enum UPOS {
26 ADJ,
28 ADP,
30 ADV,
32 AUX,
34 CCONJ,
36 DET,
38 INTJ,
40 #[default]
42 NOUN,
43 NUM,
45 PART,
47 PRON,
49 PROPN,
51 PUNCT,
53 SCONJ,
55 SYM,
57 VERB,
59}
60
61impl UPOS {
62 pub fn from_conllu(other: rs_conllu::UPOS) -> Option<Self> {
63 Some(match other {
64 rs_conllu::UPOS::ADJ => UPOS::ADJ,
65 rs_conllu::UPOS::ADP => UPOS::ADP,
66 rs_conllu::UPOS::ADV => UPOS::ADV,
67 rs_conllu::UPOS::AUX => UPOS::AUX,
68 rs_conllu::UPOS::CCONJ => UPOS::CCONJ,
69 rs_conllu::UPOS::DET => UPOS::DET,
70 rs_conllu::UPOS::INTJ => UPOS::INTJ,
71 rs_conllu::UPOS::NOUN => UPOS::NOUN,
72 rs_conllu::UPOS::NUM => UPOS::NUM,
73 rs_conllu::UPOS::PART => UPOS::PART,
74 rs_conllu::UPOS::PRON => UPOS::PRON,
75 rs_conllu::UPOS::PROPN => UPOS::PROPN,
76 rs_conllu::UPOS::PUNCT => UPOS::PUNCT,
77 rs_conllu::UPOS::SCONJ => UPOS::SCONJ,
78 rs_conllu::UPOS::SYM => UPOS::SYM,
79 rs_conllu::UPOS::VERB => UPOS::VERB,
80 rs_conllu::UPOS::X => return None,
81 })
82 }
83
84 pub fn is_nominal(&self) -> bool {
85 matches!(self, Self::NOUN | Self::PROPN | Self::PRON)
86 }
87}
88
89impl Display for UPOS {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 let desc = match self {
92 UPOS::ADJ => "Adjective",
93 UPOS::ADP => "Adposition",
94 UPOS::ADV => "Adverb",
95 UPOS::AUX => "Auxiliary",
96 UPOS::CCONJ => "Coordinating conjunction",
97 UPOS::DET => "Determiner",
98 UPOS::INTJ => "Interjection",
99 UPOS::NOUN => "Noun",
100 UPOS::NUM => "Numeral",
101 UPOS::PART => "Particle",
102 UPOS::PRON => "Pronoun",
103 UPOS::PROPN => "Proper noun",
104 UPOS::PUNCT => "Punctuation",
105 UPOS::SCONJ => "Subordinating conjunction",
106 UPOS::SYM => "Symbol",
107 UPOS::VERB => "Verb",
108 };
109 write!(f, "{desc}")
110 }
111}