comtravo / ctparse

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

Returning invalid values when input is wrong #134

Open VivekMahale-TFT opened 1 year ago

VivekMahale-TFT commented 1 year ago

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

What I did do?

I encountered issues with ctparse while using it for natural language date and time processing, especially with return dates. When attempting date-time validation, I observed problems with ctparse not providing None responses for incorrect inputs, sometimes generating random dates.

I have attached image for reference:

The examples one is correct,

Screenshot from 2023-11-03 16-29-17

I plan to raise this issue on GitHub and seek a solution if possible.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
sebastianmika commented 1 year ago

Hi,

thanks for sharing your feedback. However, I am afraid there is no straight forward solution to your problem, at least none that I am seeing. ctparse by nature is not perfect but rather tries to generate the best possible match. I.e. as long as there is one rule that generates at least one production, that will be returned.

To mitigate your issue you can build auxiallary logic on the meta data in the response:

res = ctparse("how are you?")
# the score can be understood as log-quality - very small values like this are a sign of low quality
res.score
# how much of the original text was used for this response? If that is just a small part (here 1/4) there is likely something fishy
len(res.resolution) / len("how are you?")

I hope that helps.