ctparse icon indicating copy to clipboard operation
ctparse copied to clipboard

parsing time intervals incorrectly

Open inferense opened this issue 4 years ago • 2 comments

  • ctparse - Parse natural language time expressions in pytho version: 0.3.0
  • Python version: 3.8
  • Operating System: macOS BigSur

Description

Time intervals where first int is larger than the 2nd int like in "tomorrow 9-5" are parsed always incorrectly. In such case this should result in a resolution of 9am-5pm (as there's no other feasible case for that parse). Instead, this parses the 2nd int as the next day end_time. Assuming this is due to the 24 hour system the parser uses.

r = ctparse("tomorrow 9-5")
r
Out[8]: CTParse(2021-02-23 09:00 (X/X) - 2021-02-24 05:00 (X/X), (114, 128, 136, 128, 'ruleHHMM', 'ruleHHMM', 'ruleTODTOD', 'ruleTomorrow', 'ruleDateInterval'), 4.300637883728172)

inferense avatar Feb 22 '21 20:02 inferense

I have fixed this, happy to make a pr if you're interested.

r = ctparse('tomorrow 9-5')
Out[27]: CTParse(2021-02-24 09:00 (X/X) - 2021-02-24 17:00 (X/X), (114, 128, 136, 128, 'ruleHHMM', 'ruleHHMM', 'ruleTODTOD', 'ruleTomorrow', 'ruleDateInterval'), 4.300637883728172)

inferense avatar Feb 23 '21 19:02 inferense

Thank a lot for the effort.

I mostly agree with you proposal, but I am not entirely sure it is that straight forward. That is maybe driven by the application we have designed ctparse to work for - travel booking requests. If someone sends e.g. (and probably only then) flight times like 24.02.2021 22:15 - 01:05 that actually crosses the date border.

Maybe share your fix and then let's see what would happen to expression like that.

sebastianmika avatar Feb 25 '21 07:02 sebastianmika