ctparse icon indicating copy to clipboard operation
ctparse copied to clipboard

The duration of "1 hour and 42 minutes" returns just 42 minutes, debug returns the values correctly

Open BenjaminAfrolabs opened this issue 5 years ago • 2 comments

  • ctparse - Parse natural language time expressions in python version:
  • Python version: 3.8
  • Operating System: Win10

Description

When calling ctparse("1 hour and 42 minutes") I expected to get a duration containing 1 hours and 42 minutes and I got back just the 42 minutes.

What I Did

Enabled debug and I got 2 duration objects, the first the hour the second the minutes

BenjaminAfrolabs avatar Jan 04 '21 15:01 BenjaminAfrolabs

what happened here is that ctparse doesn't support combining duration (as of yet), so it will just return one of the (both incorrect) matches.

one of the issue with these "combined espressions" is how to represent them, right now the representation is:

duration = value + unit

so that 1h and 30 minutes can't be represented, but it could be represented as 90 minutes.

I guess the best solution would be to:

  1. change the representation for Duration so that it can have multiple values + units (a bit like timedelta does)
  2. implement the rule that combines 1 hour + 30 minute. This should be pretty straightforward.

Durations are not working very well for a bunch of reason but we'd like to work on it soon, I apologize but I can't give you an ETA right now

gabrielelanaro avatar Jan 07 '21 12:01 gabrielelanaro

No worries on the ETA since I can get it working with the array from the debug flag and convert it into python's timedelta doing this (it does break if I add *seconds though):

duration_params = {}
for t in ctparse(duration, debug=True):
   duration_params[t.resolution.unit.value] = t.resolution.value
duration = timedelta(**duration_params)

Combined expressions might also be logical to be returned as a list

BenjaminAfrolabs avatar Jan 07 '21 12:01 BenjaminAfrolabs

Added a simple solution in #129 - closing this for now

sebastianmika avatar Nov 28 '22 09:11 sebastianmika