Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bumping aeson and making compilation work #724

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Duckling/AmountOfMoney/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import Data.Hashable
import Data.Text (Text)
import GHC.Generics
import Prelude
import qualified Data.HashMap.Strict as H

import qualified Duckling.Compat as Compat

import Duckling.Resolve (Resolve(..), Options(..))

Expand Down Expand Up @@ -204,8 +205,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand Down
20 changes: 20 additions & 0 deletions Duckling/Compat.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{-# LANGUAGE CPP #-}

module Duckling.Compat
( KM.insert
, KM.delete
, fromText
) where

# if MIN_VERSION_aeson(2, 0, 0)
import qualified Data.Aeson.KeyMap as KM
# else
import qualified Data.HashMap.Strict as KM
# endif

# if MIN_VERSION_aeson(2, 0, 0)
import Data.Aeson.Key (fromText)
# else
fromText :: Text -> Text
fromText = id
# endif
7 changes: 4 additions & 3 deletions Duckling/Distance/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ 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 qualified Duckling.Compat as Compat

import Duckling.Resolve (Resolve(..))

data Unit
Expand Down Expand Up @@ -86,8 +87,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand Down
5 changes: 4 additions & 1 deletion Duckling/Duration/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}


module Duckling.Duration.Types where

import Control.DeepSeq
Expand All @@ -27,6 +28,8 @@ import Prelude
import Duckling.Resolve (Resolve(..))
import Duckling.TimeGrain.Types (Grain(..), inSeconds)

import qualified Duckling.Compat as Compat

data DurationData = DurationData
{ value :: Int
, grain :: Grain
Expand All @@ -48,7 +51,7 @@ instance ToJSON DurationData where
[ "type" .= ("value" :: Text)
, "value" .= value
, "unit" .= grain
, showt grain .= value
, Compat.fromText (showt grain) .= value
, "normalized" .= object
[ "unit" .= ("second" :: Text)
, "value" .= inSeconds grain value
Expand Down
9 changes: 6 additions & 3 deletions Duckling/Quantity/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}


module Duckling.Quantity.Types where

import Control.DeepSeq
import Data.Aeson
import qualified Data.HashMap.Strict as H
import Data.Hashable
import Data.Text (Text)
import qualified Data.Text as Text
Expand All @@ -25,6 +26,8 @@ import Duckling.Resolve
import GHC.Generics
import Prelude

import qualified Duckling.Compat as Compat

data Unit
= Bowl
| Cup
Expand Down Expand Up @@ -118,8 +121,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand Down
8 changes: 5 additions & 3 deletions Duckling/Temperature/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}


module Duckling.Temperature.Types where

import Control.DeepSeq
Expand All @@ -20,9 +21,10 @@ 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 qualified Duckling.Compat as Compat

import Duckling.Resolve (Resolve(..))

data TemperatureUnit =
Expand Down Expand Up @@ -76,8 +78,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand Down
8 changes: 5 additions & 3 deletions Duckling/Time/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}


module Duckling.Time.Corpus
( datetime
, datetimeHoliday
Expand All @@ -18,12 +19,13 @@ module Duckling.Time.Corpus
) where

import Data.Aeson
import qualified Data.HashMap.Strict as H
import Data.Text (Text)
import qualified Data.Time.LocalTime.TimeZone.Series as Series
import Prelude
import Data.String

import qualified Duckling.Compat as Compat

import Duckling.Resolve
import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Types hiding (Month)
Expand Down Expand Up @@ -71,8 +73,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 $ Compat.delete "values" o
deleteValues _ = Object mempty

examples :: ToJSON a => (Context -> a) -> [Text] -> [Example]
examples f = examplesCustom (check f)
14 changes: 8 additions & 6 deletions Duckling/Time/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}


module Duckling.Time.Types where

import Control.DeepSeq
Expand All @@ -27,13 +28,14 @@ import Data.Tuple.Extra (both)
import GHC.Generics hiding (from, to)
import Prelude
import TextShow (showt)
import qualified Data.HashMap.Strict as H
import qualified Data.List as List
import qualified Data.Text as Text
import qualified Data.Time as Time
import qualified Data.Time.Calendar.WeekDate as Time
import qualified Data.Time.LocalTime.TimeZone.Series as Series

import qualified Duckling.Compat as Compat

import Duckling.Resolve
import Duckling.TimeGrain.Types (Grain)
import qualified Duckling.TimeGrain.Types as TG
Expand Down Expand Up @@ -180,8 +182,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand All @@ -199,12 +201,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 $ Compat.insert "values" (toJSON values) o
_ -> Object mempty
where
insertHoliday :: Maybe Text -> Object -> Object
insertHoliday Nothing obj = obj
insertHoliday (Just h) obj = H.insert "holidayBeta" (toJSON h) obj
insertHoliday (Just h) obj = Compat.insert "holidayBeta" (toJSON h) obj

-- | Return a tuple of (past, future) elements
type SeriesPredicate = TimeObject -> TimeContext -> ([TimeObject], [TimeObject])
Expand Down
7 changes: 4 additions & 3 deletions Duckling/Volume/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import GHC.Generics
import Prelude
import Duckling.Resolve (Resolve (..))
import qualified Data.Text as Text
import qualified Data.HashMap.Strict as H

import qualified Duckling.Compat as Compat

data Unit
= Gallon
Expand Down Expand Up @@ -81,8 +82,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 $ Compat.insert "type" (toJSON ("value" :: Text)) o
_ -> Object mempty
toJSON (IntervalValue (from, to)) = object
[ "type" .= ("interval" :: Text)
, "from" .= toJSON from
Expand Down
3 changes: 2 additions & 1 deletion duckling.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ library
build-depends: , base >= 4.8.2 && < 5.0
, array >= 0.5.1.1 && < 0.6
, attoparsec >= 0.13.1.0 && < 0.15
, aeson >= 0.11.3.0 && < 1.6
, aeson >= 0.11.3.0 && < 2.3.0.0
, bytestring >= 0.10.6.0 && < 0.12
, containers >= 0.5.6.2 && < 0.7
, deepseq >= 1.4.1.1 && < 1.5
Expand All @@ -896,6 +896,7 @@ library
build-depends: , regex-pcre-builtin >= 0.94.4 && < 0.96
else
build-depends: , regex-pcre >= 0.94.4 && < 0.96
other-modules: Duckling.Compat

default-language: Haskell2010
default-extensions: OverloadedStrings
Expand Down