gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.03k stars 4.43k forks source link

Create time parsing utility function #318

Closed gunthercox closed 7 years ago

gunthercox commented 7 years ago

It would be useful to have access to a utility function that could parse date time objects out of sentences. Use cases include scheduling reminders and looking up historical information.

Example input:

rmdort commented 7 years ago

I have been using NLTK timex parser to parse date and time just like https://duckling.wit.ai/ . We also parse email, url, phone numbers.

NLTK parser: https://github.com/nltk/nltk_contrib/blob/master/nltk_contrib/timex.py

Do you have an API skeleton in mind, if so i can help with this

gunthercox commented 7 years ago

For the API I was thinking of just a simple function that takes a string as input and returns a list of Python datetime objects in the order that they were found in the string. So something like:

from chatterbot.utils.parsing import datetime_parsing

dates = datetime_parsing('I have meetings on November 2nd and 3rd.')
print(dates)

>>> [datetime(xxx), datetime(yyy)]
rmdort commented 7 years ago

Noted.

Hi @gunthercox , I have a question regarding the license of this app.

  1. Can chatterbot be used for commercial purposes?
  2. What kind of License is it released under? MIT?
rmdort commented 7 years ago

This is where I am right now.

>>> from chatterbot.utils.parsing import datetime_parsing
>>> dates = datetime_parsing('I have meetings on November 2nd and 3rd. My next holiday is whole of next week. I am free this friday and I am going on leave the day after tomorrow')
>>> print (dates)
[([datetime.datetime(2016, 11, 2, 0, 0), datetime.datetime(2016, 11, 3, 0, 0)], (19, 54)), (datetime.datetime(2016, 10, 10, 16, 31, 8, 449717), (84, 108)), (datetime.date(2016, 10, 7), (120, 146)), (datetime.datetime(2016, 10, 5, 16, 31, 8, 449717), (175, 208))]

If you notice the first date object is an array of dates (since the user is referring to multiple dates), while others are not. The second object is the start and end position in the text

Yet to add tests. How do i run tests? Sorry I am coming from Javascript :)

gunthercox commented 7 years ago

ChatterBot is distributed under the BSD 3-clause licence (similar to many other Python projects such as Django). This license does allow for commercial use.

For running tests, this project uses nose. Nose can be installed with pip by running pip install nose. Tests can be run using the command nosetests and individual test files can be specified by running nosetests path/to/test/file.py

rmdort commented 7 years ago

Awesome thanks. I didnt see the license information in license.md file, thats the reason i asked.

gunthercox commented 7 years ago

Closed by https://github.com/gunthercox/ChatterBot/pull/321