Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

[EN] Intervals with differing grains #221

Open
almostimplemented opened this issue Feb 17, 2017 · 1 comment
Open

[EN] Intervals with differing grains #221

almostimplemented opened this issue Feb 17, 2017 · 1 comment

Comments

@almostimplemented
Copy link
Contributor

Example of issue:

duckling.core=> (pprint (parse :en$core "Today between 8:30 AM and 9 AM" [:time]))
({:dim :time,
  :body "Today between 8:30 AM and 9 AM",
  :value
  {:type "interval",
   :from {:value "2017-02-17T08:30:00.000-08:00", :grain :minute},
   :to {:value "2017-02-17T10:00:00.000-08:00", :grain :minute},
   :values
   ({:type "interval",
     :from {:value "2017-02-17T08:30:00.000-08:00", :grain :minute},
     :to {:value "2017-02-17T10:00:00.000-08:00", :grain :minute}})},
  :start 0,
  :end 30})

Seems like the simplest solution is to have the interval endpoint grains be decoupled. I think this also provides a more natural interpretation.

One might argue the grains should match, in which case the solution is for the :to endpoint to become (in this instance) "2017-02-17T09:01:00.000-08:00". I disagree with this, since the speaker syntax should define the grain, as is already the case with point-in-time parsing (e.g. "9 AM" has hour granularity while "9:00 AM" has minute granularity).

@almostimplemented
Copy link
Contributor Author

I've identified why the end interval is being improperly shifted by an hour. In duckling.time.obj/interval-start-end, after having determined the smallest grain of the interval endpoints, the end function is used to derive the "end instant of the time object" and is passed in the to predicate. Thus, the endpoint is computed using the grain of the to predicate, without regard to what the smallest grain is.

I have a fix for this, but it "breaks" an existing example in the corpus:

0 FAIL "by the end of next month"
    Expected {:start #object[org.joda.time.DateTime 0x581bac6b "2013-02-12T04:30:00.000-02:00"], :grain :second, :end #object[org.joda.time.DateTime 0x37a91d42 "2013-04-01T00:00:00.000-02:00"]}
    Got      {:start #object[org.joda.time.DateTime 0x32d2aa39 "2013-02-12T04:30:00.000-02:00"], :grain :second, :end #object[org.joda.time.DateTime 0x2853fc4d "2013-03-01T00:00:00.000-02:00"]}

It's not clear to me whether this is "OK" and the interpretation needs to change ... However this is a perfect example of where different grains make sense. Currently, the "within duration" rules all create from endpoints with :second granularity, discarding the grain semantics of the actual condition ("by 3PM', "by tomorrow", "by next week", "by the end of next month", ...)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant