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
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(-)
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
23 module Duckling.AmountOfMoney.Types where
25 import Control.DeepSeq
27 +import Data.Aeson as A
28 +import qualified Data.Aeson.KeyMap as AKM
30 import Data.Text (Text)
33 -import qualified Data.HashMap.Strict as H
35 import Duckling.Resolve (Resolve(..), Options(..))
37 @@ -204,8 +204,8 @@ data AmountOfMoneyValue
39 instance ToJSON AmountOfMoneyValue where
40 toJSON (SimpleValue value) = case toJSON value of
41 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
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
53 module Duckling.CreditCardNumber.Types where
55 import Control.DeepSeq
57 +import Data.Aeson as A
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
66 module Duckling.Distance.Types where
68 import Control.DeepSeq
70 +import Data.Aeson as A
71 +import Data.Aeson.KeyMap as AKM
73 import Data.Text (Text)
76 -import qualified Data.HashMap.Strict as H
77 import qualified Data.Text as Text
79 import Duckling.Resolve (Resolve(..))
80 @@ -86,8 +86,8 @@ data DistanceValue
82 instance ToJSON DistanceValue where
83 toJSON (SimpleValue value) = case toJSON value of
84 - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
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
97 import Control.DeepSeq
99 +import qualified Data.Aeson.Key as AK
101 import Data.Semigroup
102 import Data.Text (Text)
103 @@ -48,7 +49,7 @@ instance ToJSON DurationData where
104 [ "type" .= ("value" :: Text)
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
117 module Duckling.Quantity.Types where
119 import Control.DeepSeq
121 -import qualified Data.HashMap.Strict as H
122 +import Data.Aeson as A
123 +import qualified Data.Aeson.KeyMap as AKM
125 import Data.Text (Text)
126 import qualified Data.Text as Text
127 @@ -118,8 +118,8 @@ data QuantityValue
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
144 import Control.DeepSeq
146 +import qualified Data.Aeson.KeyMap as AKM
148 import Data.Text (Text)
151 -import qualified Data.HashMap.Strict as H
152 import qualified Data.Text as Text
154 import Duckling.Resolve (Resolve(..))
155 @@ -76,8 +76,8 @@ data TemperatureValue
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
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
181 @@ -71,8 +71,8 @@ check f context Resolved{rval = RVal _ v} = case toJSON v of
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
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
198 import Control.DeepSeq
200 +import qualified Data.Aeson.KeyMap as AKM
201 import Data.Foldable (find)
204 @@ -180,8 +181,8 @@ instance ToJSON InstantValue where
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
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
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
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
236 module Duckling.Volume.Types where
238 import Control.DeepSeq
240 +import Data.Aeson as A
241 +import Data.Aeson.KeyMap as AKM
243 import Data.Text (Text)
246 import Duckling.Resolve (Resolve (..))
247 import qualified Data.Text as Text
248 -import qualified Data.HashMap.Strict as H
252 @@ -81,8 +81,8 @@ data VolumeValue
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