1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Word {
6 pub w: String,
8 pub p: Option<u32>,
10 pub f: Option<f64>,
12 pub c: Option<usize>,
14 pub s: Option<bool>,
16 pub ow: Option<String>,
18 pub op: Option<u32>,
20 pub m: Option<Vec<Word>>,
22 pub auto_create: bool,
24 pub os: Option<bool>,
26}
27
28impl Word {
29 pub fn new(w: impl Into<String>) -> Self {
30 Self {
31 w: w.into(),
32 ..Default::default()
33 }
34 }
35
36 pub fn with_p(mut self, p: u32) -> Self {
37 self.p = Some(p);
38 self
39 }
40
41 pub fn with_f(mut self, f: f64) -> Self {
42 self.f = Some(f);
43 self
44 }
45
46 pub fn with_c(mut self, c: usize) -> Self {
47 self.c = Some(c);
48 self
49 }
50
51 pub fn is_recognized(&self) -> bool {
53 self.p.unwrap_or(0) > 0
54 }
55
56 pub fn has_pos(&self) -> bool {
58 self.p.is_some()
59 }
60
61 pub fn pos(&self) -> u32 {
62 self.p.unwrap_or(0)
63 }
64
65 pub fn freq(&self) -> f64 {
66 self.f.unwrap_or(0.0)
67 }
68
69 pub fn pos_falsy(&self) -> bool {
71 self.p.unwrap_or(0) == 0
72 }
73}
74
75pub fn stringify(words: &[Word]) -> String {
77 words.iter().map(|w| w.w.as_str()).collect()
78}
79
80pub fn stringify_list(words: &[Word]) -> Vec<String> {
82 words.iter().map(|w| w.w.clone()).collect()
83}