1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Deserialize, Serialize, Debug)]
9pub enum Book {
10 #[serde(rename = "pu")]
11 Pu,
12 #[serde(rename = "ku suli")]
13 KuSuli,
14 #[serde(rename = "ku lili")]
15 KuLili,
16 #[serde(rename = "none")]
17 None,
18}
19
20impl From<&str> for Book {
21 fn from(s: &str) -> Self {
22 match s {
23 "pu" => Book::Pu,
24 "ku suli" => Book::KuSuli,
25 "ku lili" => Book::KuLili,
26 _ => Book::None,
27 }
28 }
29}
30
31impl ToString for Book {
32 fn to_string(&self) -> String {
33 match self {
34 Book::Pu => "pu",
35 Book::KuSuli => "ku suli",
36 Book::KuLili => "ku lili",
37 Book::None => "none",
38 }
39 .into()
40 }
41}
42
43#[derive(Deserialize, Serialize, Debug)]
44pub enum CoinedEra {
45 #[serde(rename = "pre-pu")]
46 PrePu,
47 #[serde(rename = "post-pu")]
48 PostPu,
49 #[serde(rename = "post-ku")]
50 PostKu,
51 #[serde(rename = "none")]
52 None,
53}
54
55impl From<&str> for CoinedEra {
56 fn from(s: &str) -> Self {
57 match s {
58 "pre-pu" => CoinedEra::PrePu,
59 "post-pu" => CoinedEra::PostPu,
60 "post-ku" => CoinedEra::PostKu,
61 _ => CoinedEra::None,
62 }
63 }
64}
65
66impl ToString for CoinedEra {
67 fn to_string(&self) -> String {
68 match self {
69 CoinedEra::PrePu => "pre-pu",
70 CoinedEra::PostPu => "post-pu",
71 CoinedEra::PostKu => "post-ku",
72 CoinedEra::None => "none",
73 }
74 .into()
75 }
76}
77
78#[derive(Deserialize, Serialize, Debug)]
79pub struct Resources {
80 pub sona_pona: Option<String>,
81 pub lipamanka_semantic: Option<String>,
82}
83
84impl From<HashMap<String, String>> for Resources {
85 fn from(h: HashMap<String, String>) -> Self {
86 Resources {
87 sona_pona: h.get("sona_pona").map(|s| s.to_string()),
88 lipamanka_semantic: h.get("lipamanka_semantic").map(|s| s.to_string()),
89 }
90 }
91}
92
93#[derive(Deserialize, Serialize, Debug)]
94pub struct Representations {
95 pub sitelen_emosi: Option<String>,
96 pub sitelen_jelo: Option<Vec<String>>,
97 pub ligatures: Option<Vec<String>>,
98 pub sitelen_sitelen: Option<String>,
99 pub ucsur: Option<String>,
100}
101
102#[derive(Deserialize, Serialize, Debug)]
103pub enum UsageCategory {
104 #[serde(rename = "core")]
105 Core,
106 #[serde(rename = "common")]
107 Common,
108 #[serde(rename = "uncommon")]
109 Uncommon,
110 #[serde(rename = "obscure")]
111 Obscure,
112 #[serde(rename = "sandbox")]
113 Sandbox,
114}
115
116impl From<&str> for UsageCategory {
117 fn from(s: &str) -> Self {
118 match s {
119 "core" => UsageCategory::Core,
120 "common" => UsageCategory::Common,
121 "uncommon" => UsageCategory::Uncommon,
122 "obscure" => UsageCategory::Obscure,
123 _ => UsageCategory::Sandbox, }
125 }
126}
127
128impl ToString for UsageCategory {
129 fn to_string(&self) -> String {
130 match self {
131 UsageCategory::Core => "core",
132 UsageCategory::Common => "common",
133 UsageCategory::Uncommon => "uncommon",
134 UsageCategory::Obscure => "obscure",
135 UsageCategory::Sandbox => "sandbox",
136 }
137 .into()
138 }
139}
140
141#[derive(Deserialize, Serialize, Debug)]
142pub struct Etymology {
143 pub word: Option<String>,
144 pub alt: Option<String>,
145}
146
147#[derive(Deserialize, Serialize, Debug)]
148pub struct Audio {
149 pub link: String,
150 pub author: String,
151}
152
153#[derive(Deserialize, Serialize, Debug)]
154pub struct PuVerbatim {
155 pub en: String,
156 pub fr: String,
157 pub de: String,
158 pub eo: String,
159}
160
161#[derive(Deserialize, Serialize, Debug)]
162pub struct Translation {
163 pub commentary: String,
164 pub definition: String,
165 pub etymology: Vec<InnerEtymologyTranslation>,
166 pub sp_etymology: String,
167}
168
169#[derive(Deserialize, Serialize, Debug)]
170pub struct Word {
171 pub id: String,
172 pub author_verbatim: String,
173 pub author_verbatim_source: String,
174 pub book: Book,
175 pub coined_era: CoinedEra,
176 pub coined_year: String,
177 pub creator: Vec<String>,
178 pub ku_data: Option<HashMap<String, u8>>,
179 pub see_also: Vec<String>,
180 pub resources: Option<Resources>,
181 pub representations: Option<Representations>,
182 pub source_language: String,
183 pub usage_category: UsageCategory,
184 pub word: String,
185 pub deprecated: bool,
186 pub etymology: Vec<Etymology>,
187 pub audio: Vec<Audio>,
188 pub pu_verbatim: Option<PuVerbatim>,
189 pub usage: HashMap<String, u8>,
190 pub translations: HashMap<String, Translation>,
191}
192
193pub type Words = HashMap<String, Word>;
194
195pub type CommentaryTranslation = HashMap<String, String>;
196pub type DefinitionTranslation = HashMap<String, String>;
197pub type SitelenPonaTranslation = HashMap<String, String>;
198
199#[derive(Deserialize, Serialize, Debug)]
200pub struct InnerEtymologyTranslation {
201 pub definition: Option<String>,
202 pub language: String,
203}
204
205pub type EtymologyTranslation = HashMap<String, InnerEtymologyTranslation>;
206
207#[derive(Deserialize, Serialize, Debug)]
208pub struct SignEtymology {
209 pub language: String,
210 pub sign: String,
211}
212
213#[derive(Deserialize, Serialize, Debug)]
214pub struct SignWriting {
215 pub fsw: String,
216 pub swu: String,
217}
218
219#[derive(Deserialize, Serialize, Debug)]
220pub struct Video {
221 pub mp4: String,
222 pub gif: String,
223}
224
225#[derive(Deserialize, Serialize, Debug)]
226pub struct Sign {
227 pub definition: String,
228 pub id: String,
229 pub is_two_handed: bool,
230 pub new_gloss: String,
231 pub old_gloss: String,
232 pub etymology: Vec<SignEtymology>,
233 pub signwriting: SignWriting,
234 pub video: Video,
235 pub translations: ParametersTranslation,
236}
237
238pub type FingerspellingSign = Sign;
239pub type Signs = HashMap<String, Sign>;
240
241#[derive(Deserialize, Serialize, Debug)]
242pub struct InnerParametersTranslation {
243 pub handshape: Option<String>,
244 pub movement: Option<String>,
245 pub placement: Option<String>,
246 pub orientation: Option<String>,
247}
248
249pub type ParametersTranslation = HashMap<String, InnerParametersTranslation>;
250pub type IconTranslation = HashMap<String, String>;
251
252#[derive(Deserialize, Serialize, Debug)]
253pub enum WritingSystem {
254 #[serde(rename = "sitelen pona")]
255 SitelenPona,
256 #[serde(rename = "sitelen sitelen")]
257 SitelenSitelen,
258 #[serde(rename = "alphabet")]
259 Alphabet,
260 #[serde(rename = "syllabary")]
261 Syllabary,
262 #[serde(rename = "logography")]
263 Logography,
264 #[serde(rename = "tokiponido alphabet")]
265 TokiponidoAlphabet,
266 #[serde(rename = "tokiponido syllabary")]
267 TokiponidoSyllabary,
268 #[serde(rename = "tokiponido logography")]
269 TokiponidoLogography,
270}
271
272#[derive(Deserialize, Serialize, Debug)]
273pub struct Links {
274 fontfile: Option<String>,
275 repo: Option<String>,
276 webpage: Option<String>,
277}
278
279#[derive(Deserialize, Serialize, Debug)]
280pub struct Font {
281 pub id: String,
282 pub creator: Vec<String>,
283 pub features: Vec<String>,
284 pub filename: String,
285 pub last_updated: Option<String>,
286 pub license: String,
287 pub ligatures: bool,
288 pub name: String,
289 pub style: String,
290 pub ucsur: bool,
291 pub version: String,
292 pub writing_system: WritingSystem,
293 pub links: Links,
294}
295
296#[derive(Deserialize, Serialize, Debug)]
297pub enum Direction {
298 #[serde(rename = "ltr")]
299 Ltr,
300 #[serde(rename = "rtl")]
301 Rtl,
302}
303
304impl From<&str> for Direction {
305 fn from(s: &str) -> Self {
306 match s {
307 "ltr" => Direction::Ltr,
308 _ => Direction::Rtl,
309 }
310 }
311}
312
313impl ToString for Direction {
314 fn to_string(&self) -> String {
315 match self {
316 Direction::Ltr => "ltr",
317 Direction::Rtl => "rtl",
318 }
319 .into()
320 }
321}
322
323#[derive(Deserialize, Serialize, Debug)]
324pub struct LangName {
325 en: String,
326 tok: Option<String>,
327 endonym: Option<String>,
328}
329
330#[derive(Deserialize, Serialize, Debug)]
331pub struct Language {
332 pub id: String,
333 pub locale: String,
334 pub direction: Direction,
335 pub name: LangName,
336}
337
338pub type Languages = HashMap<String, Language>;