duckling_old
duckling_old copied to clipboard
Support recurrence expressions
Hey there!
I'd like to extend Duckling to handle general time recurrence expressions, such as "the first of each month", "5 p.m. on weekends", "every Christmas", "every 10 minutes", etc.
As for a representation, I'm thinking of using a map of time grains to values, such that the above expressions might take values {:day-of-month 1}
, {:hour-of-day 5 :day-of-week [6 7]}
, {:month 12 :day-of-month 25}
, and {:minute 10}
respectively.
The difficulty I'm running into is that intermediate representations of time are hidden in predicates and intersections-of-predicates, so they can't be easily extracted. For example, if I write a rule for [#"every" {:dim :time}]
, the latter object is a black box. I'm not sure how to get around this without either substantially rewriting the time code, or duplicating every time rule with a version that doesn't use predicates.
Does the team have any thoughts or suggestions about how to go about this? Thanks!
Hey Julius,
Many people have expressed their need for recurrence expressions, so that's definitely something we should try to handle.
The issue is, Duckling's internal representations (predicates) are designed with the goal to resolve temporal expression to absolute time values. So "next Monday" will produce something like "2015-10-05". What about recurrence expressions? We could resolve them to infinite sequences of absolute time values, but considering the apps that I think need them -- mainly calendars and schedulers -- I have the feeling that the representation you mentioned may be more helpful.
If that's the case, then the best way to go about this could be to just drop the predicate representations for recurrence expressions, and just use Duckling's probabilistic grammar to parse them.
Thanks for the reply, Alex! Ideally, I'd like to do this in a way that can result in a pull request that everyone can use (assuming nobody else is actively doing this).
On your suggestion of dropping the predicate representations for recurrences, one major challenge is that to take advantage of the expressiveness of times that already exists, we would have to duplicate the entire set of rules with a version that doesn't use predicates. I think this would make Duckling more difficult to maintain, and it would nearly double the amount of rules the parser has to try.
I have an alternative idea which is hacky but I think would come with much less code and maintenance baggage, and that's to actually induce the recurrence from a time by generating a few items from the sequence. I may actually do this for my own work so I can get something up and running fast.