From da36ab8a80e81da6635532775c436c806cbb6830 Mon Sep 17 00:00:00 2001 From: Julien Odent Date: Wed, 10 Jan 2018 15:16:55 -0800 Subject: [PATCH] Time: fix empty values for past time Summary: "yesterday" would resolve to an entity without any `values`. Reviewed By: JonCoens Differential Revision: D6697432 fbshipit-source-id: 7b15727f92703842a2995210fdeb99c00be74bc3 --- Duckling/Time/Types.hs | 20 +++++++++++--------- tests/Duckling/Time/EN/Tests.hs | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Duckling/Time/Types.hs b/Duckling/Time/Types.hs index f4ee2daa..be9a4a01 100644 --- a/Duckling/Time/Types.hs +++ b/Duckling/Time/Types.hs @@ -29,6 +29,7 @@ import GHC.Generics 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 @@ -102,16 +103,17 @@ instance Resolve TimeData where type ResolvedValue TimeData = TimeValue resolve _ TimeData {latent = True} = Nothing resolve context TimeData {timePred, notImmediate, direction} = do - t <- case ts of - (behind, []) -> listToMaybe behind - (_, ahead:nextAhead:_) + value <- case future of + [] -> listToMaybe past + ahead:nextAhead:_ | notImmediate && isJust (timeIntersect ahead refTime) -> Just nextAhead - (_, ahead:_) -> Just ahead + ahead:_ -> Just ahead + values <- Just . take 3 $ if List.null future then past else future Just $ case direction of - Nothing -> TimeValue (timeValue tzSeries t) . - map (timeValue tzSeries) $ take 3 future - Just d -> TimeValue (openInterval tzSeries d t) . - map (openInterval tzSeries d) $ take 3 future + Nothing -> TimeValue (timeValue tzSeries value) $ + map (timeValue tzSeries) values + Just d -> TimeValue (openInterval tzSeries d value) $ + map (openInterval tzSeries d) values where DucklingTime (Series.ZoneSeriesTime utcTime tzSeries) = referenceTime context refTime = TimeObject @@ -125,7 +127,7 @@ instance Resolve TimeData where , maxTime = timePlus refTime TG.Year 2000 , minTime = timePlus refTime TG.Year $ - 2000 } - ts@(_, future) = runPredicate timePred refTime tc + (past, future) = runPredicate timePred refTime tc timedata' :: TimeData timedata' = TimeData diff --git a/tests/Duckling/Time/EN/Tests.hs b/tests/Duckling/Time/EN/Tests.hs index 0b582f4b..b8cf85d6 100644 --- a/tests/Duckling/Time/EN/Tests.hs +++ b/tests/Duckling/Time/EN/Tests.hs @@ -145,6 +145,7 @@ valuesTest = testCase "Values Test" $ [ "now" , "8 o'clock tonight" , "tonight at 8 o'clock" + , "yesterday" ] parseValuesSize :: Value -> Maybe Int parseValuesSize x = length <$> parseValues x