comtravo / ctparse

Parse natural language time expressions in python
https://www.comtravo.com
MIT License
131 stars 24 forks source link

Parsing expressions like `29/Nov/2016` fails #45

Closed sebastianmika closed 6 years ago

sebastianmika commented 6 years ago

Copied from wrong issue, originally created by @GeniaSh (thanks for reporting!)


Hi, some dates are not read, for example " 29/ Nov/2016" whereas they are common.

Furthermore, the method for calling the datetime object (def dt(self):) should check whether year, month, day are found, now we get an error when the date is not complete.

Please see the example below.

val = ctparse('whatever dat: 29/ Nov/2016',datetime.now()) print(val)

2016-X-X X:X (X/X) s=-3.393 p=(111, 'ruleYear')

val.resolution.dt

Typ eError: an integer is required (got type NoneType) TypeError Traceback (most recent call last) in engine ----> 1 val.resolution.dt

/home/XXXX/.local/lib/python3.6/site-packages/ctparse/types.py in dt(self) 260 return datetime(self.year, self.month, self.day, 261 self.hour or 0, --> 262 self.minute or 0) 263 264

TypeError: an integer is required (got type NoneType)

sebastianmika commented 6 years ago

Hi @GeniaSh, I add a small fix for parsing expressions like 26/Nov/2016, and thanks again for reporting. It is included in ctparse >= 0.0.33.

However, your example will still not parse correctly because of the extra space (i.e. after the 29/ here 29/ Nov/2016). I do not see a simple fix for that but I will try spend some time on dealing with this kind of typos. Please also note that ctparse can be used to find the time expression in a longer text like your example 'whatever dat: 29/ Nov/2016'- but it is not really meant to do so. I would suggest to rather use e.g. a CRF to find only the relevant substring then ask ctparse to interpret it.