]> Git — Sourcephile - julm/worksheets.git/blob - src/Wiktionary.hs
update
[julm/worksheets.git] / src / Wiktionary.hs
1 {-# LANGUAGE StrictData #-}
2
3 module Wiktionary where
4
5 -- import Data.List qualified as List
6 import Utils.Generics qualified as Gen
7 import Utils.JSON qualified as JSON
8 import Utils.Prelude
9 import Utils.SQL qualified as SQL
10
11 import Control.Monad.Trans.Reader (ReaderT (..))
12 import Control.Monad.Trans.State.Strict (StateT (..))
13 import Database.SQLite.Simple.Internal (RowParser (..))
14
15 -- import Data.ByteString (ByteString)
16 -- import Database.SQLite3 qualified as SQL.Base
17 -- import Database.SQLite3.Direct qualified as SQL.Direct
18 -- import Database.SQLite3.Bindings qualified as SQL.Direct.Bindings
19 -- import Control.Exception (bracket)
20 -- import Data.Text.Encoding qualified as Text
21
22 -- | Tries to follow the schema at:
23 -- https://kaikki.org/dictionary/errors/mapping/index.html
24 data Wiktionary = Wiktionary
25 { wiktionary_abbreviation :: Maybe [Abbreviation]
26 , wiktionary_anagrams :: Maybe [Anagram]
27 , wiktionary_antonyms :: Maybe JSON.Value
28 , wiktionary_categories :: Maybe [ShortText]
29 , wiktionary_derived :: Maybe JSON.Value
30 , wiktionary_etymology_examples :: Maybe JSON.Value
31 , wiktionary_etymology_texts :: [ShortText]
32 , wiktionary_forms :: Maybe [Form]
33 , wiktionary_holonyms :: Maybe JSON.Value
34 , wiktionary_hypernyms :: Maybe JSON.Value
35 , wiktionary_hyponyms :: Maybe JSON.Value
36 , wiktionary_lang :: Maybe ShortText
37 , wiktionary_lang_code :: Maybe ShortText
38 , wiktionary_meronyms :: Maybe JSON.Value
39 , wiktionary_notes :: Maybe JSON.Value
40 , wiktionary_paronyms :: Maybe JSON.Value
41 , wiktionary_pos :: Maybe ShortText
42 , wiktionary_pos_title :: Maybe ShortText
43 , wiktionary_proverbs :: Maybe JSON.Value
44 , wiktionary_raw_tags :: Maybe [ShortText]
45 , wiktionary_redirect :: Maybe ShortText
46 , wiktionary_related :: Maybe JSON.Value
47 , wiktionary_senses :: Maybe [Sense]
48 , wiktionary_sounds :: [Sound]
49 , wiktionary_synonyms :: Maybe [Synonym]
50 , wiktionary_tags :: Maybe [ShortText]
51 , wiktionary_title :: Maybe JSON.Value
52 , wiktionary_translations :: Maybe JSON.Value
53 , wiktionary_troponyms :: Maybe JSON.Value
54 , wiktionary_word :: Maybe ShortText
55 -- ^ Yes, the word can be missing,
56 -- eg. when `wiktionary_pos` is `"hard-redirect"`.
57 }
58 deriving (Eq, Show, Generic)
59 deriving
60 (JSON.ToJSON, JSON.FromJSON)
61 via (JSON.GenericallyWithOptions Wiktionary)
62 deriving
63 (SQL.ToRow {-, SQL.FromRow-})
64 via (SQL.GenericallyWithOptions Wiktionary)
65
66 instance SQL.FromRow Wiktionary where
67 fromRow = SQL.gfromRowWithErrorContext <&> Gen.to
68
69 data Anagram = Anagram
70 { anagram_word :: ShortText
71 }
72 deriving (Eq, Show, Generic)
73 deriving
74 (JSON.ToJSON, JSON.FromJSON)
75 via (JSON.GenericallyWithOptions Anagram)
76
77 data Sense = Sense
78 { sense_alt_of :: Maybe JSON.Value
79 , sense_categories :: Maybe [ShortText]
80 , sense_examples :: Maybe JSON.Value
81 , sense_form_of :: Maybe JSON.Value
82 , sense_glosses :: Maybe [ShortText]
83 , sense_note :: Maybe JSON.Value
84 , sense_raw_tags :: Maybe JSON.Value
85 , sense_tags :: Maybe JSON.Value
86 , sense_topics :: Maybe JSON.Value
87 }
88 deriving (Eq, Show, Generic)
89 deriving
90 (JSON.ToJSON, JSON.FromJSON)
91 via (JSON.GenericallyWithOptions Sense)
92
93 data Synonym = Synonym
94 { synonym_alt :: Maybe JSON.Value
95 , synonym_raw_tags :: Maybe JSON.Value
96 , synonym_roman :: Maybe JSON.Value
97 , synonym_sense :: Maybe JSON.Value
98 , synonym_sense_index :: Maybe JSON.Value
99 , synonym_tags :: Maybe JSON.Value
100 , synonym_topics :: Maybe JSON.Value
101 , synonym_translation :: Maybe JSON.Value
102 , synonym_word :: ShortText
103 }
104 deriving (Eq, Show, Generic)
105 deriving
106 (JSON.ToJSON, JSON.FromJSON)
107 via (JSON.GenericallyWithOptions Synonym)
108
109 data Abbreviation = Abbreviation
110 { abbreviation_raw_tags :: Maybe JSON.Value
111 , abbreviation_roman :: Maybe ShortText
112 , abbreviation_sense :: Maybe JSON.Value
113 , abbreviation_sense_index :: Maybe JSON.Value
114 , abbreviation_tags :: Maybe JSON.Value
115 , abbreviation_topics :: Maybe JSON.Value
116 , abbreviation_translation :: Maybe JSON.Value
117 , abbreviation_word :: Maybe ShortText
118 }
119 deriving (Eq, Show, Generic)
120 deriving
121 (JSON.ToJSON, JSON.FromJSON)
122 via (JSON.GenericallyWithOptions Abbreviation)
123
124 data Form = Form
125 { form_form :: ShortText
126 , form_ipas :: Maybe [ShortText]
127 , form_raw_tags :: Maybe JSON.Value
128 , form_sense :: Maybe JSON.Value
129 , form_sense_index :: Maybe JSON.Value
130 , form_source :: Maybe ShortText
131 , form_tags :: Maybe [ShortText]
132 , form_hiragana :: Maybe ShortText
133 , form_roman :: Maybe ShortText
134 }
135 deriving (Eq, Show, Generic)
136 deriving
137 (JSON.ToJSON, JSON.FromJSON)
138 via (JSON.GenericallyWithOptions Form)
139
140 data Sound = Sound
141 { sound_audio :: Maybe ShortText
142 , sound_homophone :: Maybe JSON.Value
143 , sound_ipa :: Maybe ShortText
144 , sound_mp3_url :: Maybe ShortText
145 , sound_oga_url :: Maybe ShortText
146 , sound_opus_url :: Maybe ShortText
147 , sound_ogg_url :: Maybe ShortText
148 , sound_flac_url :: Maybe ShortText
149 , sound_raw_tags :: Maybe [ShortText]
150 , sound_rhymes :: Maybe JSON.Value
151 , sound_roman :: Maybe JSON.Value
152 , sound_tags :: Maybe JSON.Value
153 , sound_wav_url :: Maybe ShortText
154 , sound_zh_pron :: Maybe JSON.Value
155 }
156 deriving (Eq, Show, Generic)
157 deriving
158 (JSON.ToJSON, JSON.FromJSON)
159 via (JSON.GenericallyWithOptions Sound)
160
161 type LangCode = ShortText