facebook/duckling

Wrong interpretations of sentences with word "now"

Open

#440 opened on Dec 10, 2019

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Haskell (4,282 stars) (737 forks)batch import
bughelp wantedquestion

Description

Hi,

For below sentences where word "now" is replaced with some other word duckling can handle a sentence as a whole and interpretation is correct. But "now" is special.... and duckling cannot handle sentence as a whole.

"Three days from today at 6pm" -> {vValue = 2013-02-15 18:00:00 -0200, vGrain = Hour}

Debug view:

*Duckling.Debug> debug (makeLocale EN $ Just US) "Three days from today at 6pm" [This Time]
<duration> after|before|from|past <time> (Three days from today at 6pm)
-- <integer> <unit-of-duration> (Three days)
-- -- integer (0..19) (Three)
-- -- -- regex (Three)
-- -- day (grain) (days)
-- -- -- regex (days)
-- regex (from)
-- intersect (today at 6pm)
-- -- today (today)
-- -- -- regex (today)
-- -- at <time-of-day> (at 6pm)
-- -- -- regex (at)
-- -- -- <time-of-day> am|pm (6pm)
-- -- -- -- time-of-day (latent) (6)
-- -- -- -- -- integer (numeric) (6)
-- -- -- -- -- -- regex (6)
-- -- -- -- regex (pm)

"Three days from now at 6pm" -> {vValue = 2013-02-15 04:00:00 -0200, vGrain = Hour}

<duration> after|before|from|past <time> (Three days from now)
-- <integer> <unit-of-duration> (Three days)
-- -- integer (0..19) (Three)
-- -- -- regex (Three)
-- -- day (grain) (days)
-- -- -- regex (days)
-- regex (from)
-- now (now)
-- -- regex (now)
at <time-of-day> (at 6pm)
-- regex (at)
-- <time-of-day> am|pm (6pm)
-- -- time-of-day (latent) (6)
-- -- -- integer (numeric) (6)
-- -- -- -- regex (6)
-- -- regex (pm)

"Four days from Wednesday at 16:00" -> {vValue = 2013-02-17 16:00:00 -0200, vGrain = Minute}

intersect (Four days from Wednesday at 16:00)
-- <duration> after|before|from|past <time> (Four days from Wednesday)
-- -- <integer> <unit-of-duration> (Four days)
-- -- -- integer (0..19) (Four)
-- -- -- -- regex (Four)
-- -- -- day (grain) (days)
-- -- -- -- regex (days)
-- -- regex (from)
-- -- Wednesday (Wednesday)
-- -- -- regex (Wednesday)
-- at <time-of-day> (at 16:00)
-- -- regex (at)
-- -- hh:mm (16:00)
-- -- -- regex (16:00)

"Four days from now at 16:00" -> {vValue = 2013-02-16 04:00:00 -0200, vGrain = Hour}

<duration> after|before|from|past <time> (Four days from now)
-- <integer> <unit-of-duration> (Four days)
-- -- integer (0..19) (Four)
-- -- -- regex (Four)
-- -- day (grain) (days)
-- -- -- regex (days)
-- regex (from)
-- now (now)
-- -- regex (now)
at <time-of-day> (at 16:00)
-- regex (at)
-- hh:mm (16:00)
-- -- regex (16:00)

"in two days from yesterday after 20:00" -> {vValue = 2013-02-13 20:00:00 -0200, vGrain = Minute}

in|within|after <duration> (in two days)
-- regex (in)
-- <integer> <unit-of-duration> (two days)
-- -- integer (0..19) (two)
-- -- -- regex (two)
-- -- day (grain) (days)
-- -- -- regex (days)
intersect (two days from yesterday after 20:00)
-- <duration> after|before|from|past <time> (two days from yesterday)
-- -- <integer> <unit-of-duration> (two days)
-- -- -- integer (0..19) (two)
-- -- -- -- regex (two)
-- -- -- day (grain) (days)
-- -- -- -- regex (days)
-- -- regex (from)
-- -- yesterday (yesterday)
-- -- -- regex (yesterday)
-- from|since|after <time> (after 20:00)
-- -- regex (after)
-- -- hh:mm (20:00)
-- -- -- regex (20:00)

"in two days from now after 20:00" -> {vValue = 2013-02-14 04:00:00 -0200, vGrain = Hour}

*Duckling.Debug> debug (makeLocale EN $ Just US) "in two days from now after 20:00" [This Time]
in|within|after <duration> (in two days)
-- regex (in)
-- <integer> <unit-of-duration> (two days)
-- -- integer (0..19) (two)
-- -- -- regex (two)
-- -- day (grain) (days)
-- -- -- regex (days)
<duration> after|before|from|past <time> (two days from now)
-- <integer> <unit-of-duration> (two days)
-- -- integer (0..19) (two)
-- -- -- regex (two)
-- -- day (grain) (days)
-- -- -- regex (days)
-- regex (from)
-- now (now)
-- -- regex (now)
from|since|after <time> (after 20:00)
-- regex (after)
-- hh:mm (20:00)
-- -- regex (20:00)

From my poor understanding of a code this is because "now" has TG.Seconds and durations are represented in Days. In result existing rules cannot properly interpret "now" as their time shift reference.

https://github.com/facebook/duckling/blob/0ebaf378dc3dd93a57a567298eea9fb73a7d0e7c/Duckling/Time/EN/Rules.hs#L130-L145

https://github.com/facebook/duckling/blob/0ebaf378dc3dd93a57a567298eea9fb73a7d0e7c/Duckling/Time/EN/Rules.hs#L2322-L2340

I've tried to create a rule which will try to convert type of "now" from TG.Second to TG.Days but failed miserably (compilations errors, wrong type, wrong result time). Could you provide me some help from more advanced Haskell programmer how should I handle this special case?

Thank you in advance

Contributor guide