]> Git — Sourcephile - gargantext.git/blob - patches/duckling/0002-support-and-require-aeson-2.0.patch
build: add nix flake support
[gargantext.git] / patches / duckling / 0002-support-and-require-aeson-2.0.patch
1 From db723932a0c0dcd11bff238382a455be59c250ac Mon Sep 17 00:00:00 2001
2 From: Julien Moutinho <julm+gargantext@sourcephile.fr>
3 Date: Sat, 1 Jul 2023 19:46:03 +0200
4 Subject: [PATCH 2/2] support and require aeson >= 2.0
5
6 ---
7 Duckling/AmountOfMoney/Types.hs | 8 ++++----
8 Duckling/CreditCardNumber/Types.hs | 2 +-
9 Duckling/Distance/Types.hs | 8 ++++----
10 Duckling/Duration/Types.hs | 3 ++-
11 Duckling/Quantity/Types.hs | 8 ++++----
12 Duckling/Temperature/Types.hs | 6 +++---
13 Duckling/Time/Corpus.hs | 8 ++++----
14 Duckling/Time/Types.hs | 11 ++++++-----
15 Duckling/Volume/Types.hs | 8 ++++----
16 9 files changed, 32 insertions(+), 30 deletions(-)
17
18 diff --git a/Duckling/AmountOfMoney/Types.hs b/Duckling/AmountOfMoney/Types.hs
19 index 803c4ff2..9a0c2b16 100644
20 --- a/Duckling/AmountOfMoney/Types.hs
21 +++ b/Duckling/AmountOfMoney/Types.hs
22 @@ -15,12 +15,12 @@
23 module Duckling.AmountOfMoney.Types where
24
25 import Control.DeepSeq
26 -import Data.Aeson
27 +import Data.Aeson as A
28 +import qualified Data.Aeson.KeyMap as AKM
29 import Data.Hashable
30 import Data.Text (Text)
31 import GHC.Generics
32 import Prelude
33 -import qualified Data.HashMap.Strict as H
34
35 import Duckling.Resolve (Resolve(..), Options(..))
36
37 @@ -204,8 +204,8 @@ data AmountOfMoneyValue
38
39 instance ToJSON AmountOfMoneyValue where
40 toJSON (SimpleValue value) = case toJSON value of
41 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
42 - _ -> Object H.empty
43 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
44 + _ -> Object AKM.empty
45 toJSON (IntervalValue (from, to)) = object
46 [ "type" .= ("interval" :: Text)
47 , "from" .= toJSON from
48 diff --git a/Duckling/CreditCardNumber/Types.hs b/Duckling/CreditCardNumber/Types.hs
49 index 5339ecac..3c5f19d3 100644
50 --- a/Duckling/CreditCardNumber/Types.hs
51 +++ b/Duckling/CreditCardNumber/Types.hs
52 @@ -15,7 +15,7 @@
53 module Duckling.CreditCardNumber.Types where
54
55 import Control.DeepSeq
56 -import Data.Aeson
57 +import Data.Aeson as A
58 import Data.Hashable
59 import Data.Text (Text)
60 import qualified Data.Text as Text
61 diff --git a/Duckling/Distance/Types.hs b/Duckling/Distance/Types.hs
62 index 1432665a..5a2dc4a9 100644
63 --- a/Duckling/Distance/Types.hs
64 +++ b/Duckling/Distance/Types.hs
65 @@ -15,12 +15,12 @@
66 module Duckling.Distance.Types where
67
68 import Control.DeepSeq
69 -import Data.Aeson
70 +import Data.Aeson as A
71 +import Data.Aeson.KeyMap as AKM
72 import Data.Hashable
73 import Data.Text (Text)
74 import GHC.Generics
75 import Prelude
76 -import qualified Data.HashMap.Strict as H
77 import qualified Data.Text as Text
78
79 import Duckling.Resolve (Resolve(..))
80 @@ -86,8 +86,8 @@ data DistanceValue
81
82 instance ToJSON DistanceValue where
83 toJSON (SimpleValue value) = case toJSON value of
84 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
85 - _ -> Object H.empty
86 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
87 + _ -> Object AKM.empty
88 toJSON (IntervalValue (from, to)) = object
89 [ "type" .= ("interval" :: Text)
90 , "from" .= toJSON from
91 diff --git a/Duckling/Duration/Types.hs b/Duckling/Duration/Types.hs
92 index b24b2aff..f1935f6d 100644
93 --- a/Duckling/Duration/Types.hs
94 +++ b/Duckling/Duration/Types.hs
95 @@ -16,6 +16,7 @@ module Duckling.Duration.Types where
96
97 import Control.DeepSeq
98 import Data.Aeson
99 +import qualified Data.Aeson.Key as AK
100 import Data.Hashable
101 import Data.Semigroup
102 import Data.Text (Text)
103 @@ -48,7 +49,7 @@ instance ToJSON DurationData where
104 [ "type" .= ("value" :: Text)
105 , "value" .= value
106 , "unit" .= grain
107 - , showt grain .= value
108 + , AK.fromText (showt grain) .= value
109 , "normalized" .= object
110 [ "unit" .= ("second" :: Text)
111 , "value" .= inSeconds grain value
112 diff --git a/Duckling/Quantity/Types.hs b/Duckling/Quantity/Types.hs
113 index 657bbcc5..8c52ce8a 100644
114 --- a/Duckling/Quantity/Types.hs
115 +++ b/Duckling/Quantity/Types.hs
116 @@ -13,8 +13,8 @@
117 module Duckling.Quantity.Types where
118
119 import Control.DeepSeq
120 -import Data.Aeson
121 -import qualified Data.HashMap.Strict as H
122 +import Data.Aeson as A
123 +import qualified Data.Aeson.KeyMap as AKM
124 import Data.Hashable
125 import Data.Text (Text)
126 import qualified Data.Text as Text
127 @@ -118,8 +118,8 @@ data QuantityValue
128
129 instance ToJSON QuantityValue where
130 toJSON (SimpleValue value) = case toJSON value of
131 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
132 - _ -> Object H.empty
133 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
134 + _ -> Object AKM.empty
135 toJSON (IntervalValue (from, to)) = object
136 [ "type" .= ("interval" :: Text)
137 , "from" .= toJSON from
138 diff --git a/Duckling/Temperature/Types.hs b/Duckling/Temperature/Types.hs
139 index 43ec337d..03432d77 100644
140 --- a/Duckling/Temperature/Types.hs
141 +++ b/Duckling/Temperature/Types.hs
142 @@ -16,11 +16,11 @@ module Duckling.Temperature.Types where
143
144 import Control.DeepSeq
145 import Data.Aeson
146 +import qualified Data.Aeson.KeyMap as AKM
147 import Data.Hashable
148 import Data.Text (Text)
149 import GHC.Generics
150 import Prelude
151 -import qualified Data.HashMap.Strict as H
152 import qualified Data.Text as Text
153
154 import Duckling.Resolve (Resolve(..))
155 @@ -76,8 +76,8 @@ data TemperatureValue
156
157 instance ToJSON TemperatureValue where
158 toJSON (SimpleValue value) = case toJSON value of
159 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
160 - _ -> Object H.empty
161 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
162 + _ -> Object AKM.empty
163 toJSON (IntervalValue (from, to)) = object
164 [ "type" .= ("interval" :: Text)
165 , "from" .= toJSON from
166 diff --git a/Duckling/Time/Corpus.hs b/Duckling/Time/Corpus.hs
167 index c1e6b293..d079c5f6 100644
168 --- a/Duckling/Time/Corpus.hs
169 +++ b/Duckling/Time/Corpus.hs
170 @@ -17,8 +17,8 @@ module Duckling.Time.Corpus
171 , examples
172 ) where
173
174 -import Data.Aeson
175 -import qualified Data.HashMap.Strict as H
176 +import Data.Aeson as A
177 +import qualified Data.Aeson.KeyMap as AKM
178 import Data.Text (Text)
179 import qualified Data.Time.LocalTime.TimeZone.Series as Series
180 import Prelude
181 @@ -71,8 +71,8 @@ check f context Resolved{rval = RVal _ v} = case toJSON v of
182 _ -> False
183 where
184 deleteValues :: Value -> Value
185 - deleteValues (Object o) = Object $ H.delete "values" o
186 - deleteValues _ = Object H.empty
187 + deleteValues (Object o) = Object $ AKM.delete "values" o
188 + deleteValues _ = Object AKM.empty
189
190 examples :: ToJSON a => (Context -> a) -> [Text] -> [Example]
191 examples f = examplesCustom (check f)
192 diff --git a/Duckling/Time/Types.hs b/Duckling/Time/Types.hs
193 index b56fdbab..2f5978b0 100644
194 --- a/Duckling/Time/Types.hs
195 +++ b/Duckling/Time/Types.hs
196 @@ -18,6 +18,7 @@ module Duckling.Time.Types where
197
198 import Control.DeepSeq
199 import Data.Aeson
200 +import qualified Data.Aeson.KeyMap as AKM
201 import Data.Foldable (find)
202 import Data.Hashable
203 import Data.Maybe
204 @@ -180,8 +181,8 @@ instance ToJSON InstantValue where
205
206 instance ToJSON SingleTimeValue where
207 toJSON (SimpleValue value) = case toJSON value of
208 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
209 - _ -> Object H.empty
210 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
211 + _ -> Object AKM.empty
212 toJSON (IntervalValue (from, to)) = object
213 [ "type" .= ("interval" :: Text)
214 , "from" .= toJSON from
215 @@ -199,12 +200,12 @@ instance ToJSON SingleTimeValue where
216 instance ToJSON TimeValue where
217 toJSON (TimeValue value values holiday) = case toJSON value of
218 Object o ->
219 - Object $ insertHoliday holiday $ H.insert "values" (toJSON values) o
220 - _ -> Object H.empty
221 + Object $ insertHoliday holiday $ AKM.insert "values" (toJSON values) o
222 + _ -> Object AKM.empty
223 where
224 insertHoliday :: Maybe Text -> Object -> Object
225 insertHoliday Nothing obj = obj
226 - insertHoliday (Just h) obj = H.insert "holidayBeta" (toJSON h) obj
227 + insertHoliday (Just h) obj = AKM.insert "holidayBeta" (toJSON h) obj
228
229 -- | Return a tuple of (past, future) elements
230 type SeriesPredicate = TimeObject -> TimeContext -> ([TimeObject], [TimeObject])
231 diff --git a/Duckling/Volume/Types.hs b/Duckling/Volume/Types.hs
232 index 7c515f9a..677a2252 100644
233 --- a/Duckling/Volume/Types.hs
234 +++ b/Duckling/Volume/Types.hs
235 @@ -15,14 +15,14 @@
236 module Duckling.Volume.Types where
237
238 import Control.DeepSeq
239 -import Data.Aeson
240 +import Data.Aeson as A
241 +import Data.Aeson.KeyMap as AKM
242 import Data.Hashable
243 import Data.Text (Text)
244 import GHC.Generics
245 import Prelude
246 import Duckling.Resolve (Resolve (..))
247 import qualified Data.Text as Text
248 -import qualified Data.HashMap.Strict as H
249
250 data Unit
251 = Gallon
252 @@ -81,8 +81,8 @@ data VolumeValue
253
254 instance ToJSON VolumeValue where
255 toJSON (SimpleValue value) = case toJSON value of
256 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
257 - _ -> Object H.empty
258 + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o
259 + _ -> Object AKM.empty
260 toJSON (IntervalValue (from, to)) = object
261 [ "type" .= ("interval" :: Text)
262 , "from" .= toJSON from
263 --
264 2.40.1
265