From db723932a0c0dcd11bff238382a455be59c250ac Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Sat, 1 Jul 2023 19:46:03 +0200 Subject: [PATCH 2/2] support and require aeson >= 2.0 --- Duckling/AmountOfMoney/Types.hs | 8 ++++---- Duckling/CreditCardNumber/Types.hs | 2 +- Duckling/Distance/Types.hs | 8 ++++---- Duckling/Duration/Types.hs | 3 ++- Duckling/Quantity/Types.hs | 8 ++++---- Duckling/Temperature/Types.hs | 6 +++--- Duckling/Time/Corpus.hs | 8 ++++---- Duckling/Time/Types.hs | 11 ++++++----- Duckling/Volume/Types.hs | 8 ++++---- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Duckling/AmountOfMoney/Types.hs b/Duckling/AmountOfMoney/Types.hs index 803c4ff2..9a0c2b16 100644 --- a/Duckling/AmountOfMoney/Types.hs +++ b/Duckling/AmountOfMoney/Types.hs @@ -15,12 +15,12 @@ module Duckling.AmountOfMoney.Types where import Control.DeepSeq -import Data.Aeson +import Data.Aeson as A +import qualified Data.Aeson.KeyMap as AKM import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H import Duckling.Resolve (Resolve(..), Options(..)) @@ -204,8 +204,8 @@ data AmountOfMoneyValue instance ToJSON AmountOfMoneyValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/CreditCardNumber/Types.hs b/Duckling/CreditCardNumber/Types.hs index 5339ecac..3c5f19d3 100644 --- a/Duckling/CreditCardNumber/Types.hs +++ b/Duckling/CreditCardNumber/Types.hs @@ -15,7 +15,7 @@ module Duckling.CreditCardNumber.Types where import Control.DeepSeq -import Data.Aeson +import Data.Aeson as A import Data.Hashable import Data.Text (Text) import qualified Data.Text as Text diff --git a/Duckling/Distance/Types.hs b/Duckling/Distance/Types.hs index 1432665a..5a2dc4a9 100644 --- a/Duckling/Distance/Types.hs +++ b/Duckling/Distance/Types.hs @@ -15,12 +15,12 @@ module Duckling.Distance.Types where import Control.DeepSeq -import Data.Aeson +import Data.Aeson as A +import Data.Aeson.KeyMap as AKM import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H import qualified Data.Text as Text import Duckling.Resolve (Resolve(..)) @@ -86,8 +86,8 @@ data DistanceValue instance ToJSON DistanceValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Duration/Types.hs b/Duckling/Duration/Types.hs index b24b2aff..f1935f6d 100644 --- a/Duckling/Duration/Types.hs +++ b/Duckling/Duration/Types.hs @@ -16,6 +16,7 @@ module Duckling.Duration.Types where import Control.DeepSeq import Data.Aeson +import qualified Data.Aeson.Key as AK import Data.Hashable import Data.Semigroup import Data.Text (Text) @@ -48,7 +49,7 @@ instance ToJSON DurationData where [ "type" .= ("value" :: Text) , "value" .= value , "unit" .= grain - , showt grain .= value + , AK.fromText (showt grain) .= value , "normalized" .= object [ "unit" .= ("second" :: Text) , "value" .= inSeconds grain value diff --git a/Duckling/Quantity/Types.hs b/Duckling/Quantity/Types.hs index 657bbcc5..8c52ce8a 100644 --- a/Duckling/Quantity/Types.hs +++ b/Duckling/Quantity/Types.hs @@ -13,8 +13,8 @@ module Duckling.Quantity.Types where import Control.DeepSeq -import Data.Aeson -import qualified Data.HashMap.Strict as H +import Data.Aeson as A +import qualified Data.Aeson.KeyMap as AKM import Data.Hashable import Data.Text (Text) import qualified Data.Text as Text @@ -118,8 +118,8 @@ data QuantityValue instance ToJSON QuantityValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Temperature/Types.hs b/Duckling/Temperature/Types.hs index 43ec337d..03432d77 100644 --- a/Duckling/Temperature/Types.hs +++ b/Duckling/Temperature/Types.hs @@ -16,11 +16,11 @@ module Duckling.Temperature.Types where import Control.DeepSeq import Data.Aeson +import qualified Data.Aeson.KeyMap as AKM import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude -import qualified Data.HashMap.Strict as H import qualified Data.Text as Text import Duckling.Resolve (Resolve(..)) @@ -76,8 +76,8 @@ data TemperatureValue instance ToJSON TemperatureValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from diff --git a/Duckling/Time/Corpus.hs b/Duckling/Time/Corpus.hs index c1e6b293..d079c5f6 100644 --- a/Duckling/Time/Corpus.hs +++ b/Duckling/Time/Corpus.hs @@ -17,8 +17,8 @@ module Duckling.Time.Corpus , examples ) where -import Data.Aeson -import qualified Data.HashMap.Strict as H +import Data.Aeson as A +import qualified Data.Aeson.KeyMap as AKM import Data.Text (Text) import qualified Data.Time.LocalTime.TimeZone.Series as Series import Prelude @@ -71,8 +71,8 @@ check f context Resolved{rval = RVal _ v} = case toJSON v of _ -> False where deleteValues :: Value -> Value - deleteValues (Object o) = Object $ H.delete "values" o - deleteValues _ = Object H.empty + deleteValues (Object o) = Object $ AKM.delete "values" o + deleteValues _ = Object AKM.empty examples :: ToJSON a => (Context -> a) -> [Text] -> [Example] examples f = examplesCustom (check f) diff --git a/Duckling/Time/Types.hs b/Duckling/Time/Types.hs index b56fdbab..2f5978b0 100644 --- a/Duckling/Time/Types.hs +++ b/Duckling/Time/Types.hs @@ -18,6 +18,7 @@ module Duckling.Time.Types where import Control.DeepSeq import Data.Aeson +import qualified Data.Aeson.KeyMap as AKM import Data.Foldable (find) import Data.Hashable import Data.Maybe @@ -180,8 +181,8 @@ instance ToJSON InstantValue where instance ToJSON SingleTimeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from @@ -199,12 +200,12 @@ instance ToJSON SingleTimeValue where instance ToJSON TimeValue where toJSON (TimeValue value values holiday) = case toJSON value of Object o -> - Object $ insertHoliday holiday $ H.insert "values" (toJSON values) o - _ -> Object H.empty + Object $ insertHoliday holiday $ AKM.insert "values" (toJSON values) o + _ -> Object AKM.empty where insertHoliday :: Maybe Text -> Object -> Object insertHoliday Nothing obj = obj - insertHoliday (Just h) obj = H.insert "holidayBeta" (toJSON h) obj + insertHoliday (Just h) obj = AKM.insert "holidayBeta" (toJSON h) obj -- | Return a tuple of (past, future) elements type SeriesPredicate = TimeObject -> TimeContext -> ([TimeObject], [TimeObject]) diff --git a/Duckling/Volume/Types.hs b/Duckling/Volume/Types.hs index 7c515f9a..677a2252 100644 --- a/Duckling/Volume/Types.hs +++ b/Duckling/Volume/Types.hs @@ -15,14 +15,14 @@ module Duckling.Volume.Types where import Control.DeepSeq -import Data.Aeson +import Data.Aeson as A +import Data.Aeson.KeyMap as AKM import Data.Hashable import Data.Text (Text) import GHC.Generics import Prelude import Duckling.Resolve (Resolve (..)) import qualified Data.Text as Text -import qualified Data.HashMap.Strict as H data Unit = Gallon @@ -81,8 +81,8 @@ data VolumeValue instance ToJSON VolumeValue where toJSON (SimpleValue value) = case toJSON value of - Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o - _ -> Object H.empty + Object o -> Object $ AKM.insert "type" (toJSON ("value" :: Text)) o + _ -> Object AKM.empty toJSON (IntervalValue (from, to)) = object [ "type" .= ("interval" :: Text) , "from" .= toJSON from -- 2.40.1