Natural Language Date Processing.

  • Thread starter Andrew Gwozdziewycz
  • Start date
A

Andrew Gwozdziewycz

I've been looking recently for date processing modules that can parse
dates in forms such as
"next week" or "6 days from next sunday". PHP has a function that
will do this called 'strtotime',
but I have not found a Python implementation. I've check the standard
date, datetime and time
modules and also mx.Date* modules. Am I overlooking something here or
does it not exist?
Anyone know of an implementation? Also, I realize that this is
perhaps very English specific
so I apologize to any non-native English speakers.
 
A

andychambers2002

From the docs for PHP's 'strtotime'

Parameters

time
The string to parse, according to the GNU Date Input Formats syntax.
Before PHP 5.0, microseconds weren't allowed in the time, since PHP 5.0
they are allowed but ignored.
....

It seems that the string to be parsed has to be provided in the GNU
date format. One option would be to provide a function that calls out
to the the GNU date program with whatever string you want to parse.

I'm not aware of an existing function in Python that does this.

Regards,
Andy
 
A

Andrew Gwozdziewycz

On 7 Feb 2006 05:51:40 -0800, (e-mail address removed)
It seems that the string to be parsed has to be provided in the GNU
date format. One option would be to provide a function that calls out
to the the GNU date program with whatever string you want to parse.

Actually, I looked at the source of the php function and it manually
parses it (i assume according to the GNU date rules). However, i'd
prefer not to have to port the function to python if someone else has
already done so, or has a more pythonic implementation.
 
S

Steven Bethard

Andrew said:
I've been looking recently for date processing modules that can parse
dates in forms such as "next week" or "6 days from next sunday".

This is, in fact, a fairly difficult problem in general. See the TERN_
competition that's currently held yearly on this task. There are a few
taggers available that do this at:

http://timex2.mitre.org/taggers/timex2_taggers.html

But none of them are available as Python modules. You might be able to
port the Perl script there, but it won't do as well as the ATEL program
from CU which uses machine learning techniques.

... _TERN: http://timex2.mitre.org/tern.html

STeVe
 
M

Michael Amrhein

Andrew said:
I've been looking recently for date processing modules that can parse
dates in forms such as
"next week" or "6 days from next sunday". PHP has a function that will
do this called 'strtotime',
but I have not found a Python implementation. I've check the standard
date, datetime and time
modules and also mx.Date* modules. Am I overlooking something here or
does it not exist?
Anyone know of an implementation? Also, I realize that this is perhaps
very English specific
so I apologize to any non-native English speakers.

---
Andrew Gwozdziewycz
(e-mail address removed)
http://ihadagreatview.org
http://plasticandroid.org

You may take a look at http://labix.org/python-dateutil
Have fun
Michael
 
M

Michael Amrhein

Andrew said:
I've been looking recently for date processing modules that can parse
dates in forms such as
"next week" or "6 days from next sunday". PHP has a function that will
do this called 'strtotime',
but I have not found a Python implementation. I've check the standard
date, datetime and time
modules and also mx.Date* modules. Am I overlooking something here or
does it not exist?
Anyone know of an implementation? Also, I realize that this is perhaps
very English specific
so I apologize to any non-native English speakers.

---
Andrew Gwozdziewycz
(e-mail address removed)
http://ihadagreatview.org
http://plasticandroid.org

You may take a look at http://labix.org/python-dateutil
Have fun
Michael
 
A

Andrew Gwozdziewycz

You may take a look at http://labix.org/python-dateutil
Have fun
Michael

Looks like it does a good job parsing dates, but doesn't seem to do
english dates. I found a javascript implementation of a few functions
that will probably be relatively easy to port to python. Whether or
not it'll perform well is another story... Thanks for the help.
 
M

Michael Amrhein

Andrew said:
Looks like it does a good job parsing dates, but doesn't seem to do
english dates. I found a javascript implementation of a few functions
that will probably be relatively easy to port to python. Whether or
not it'll perform well is another story... Thanks for the help.
datetime.datetime(2003, 4, 16, 0, 0)

Aren't these "english dates"?

Michael
 
M

Michael Amrhein

Andrew said:
Looks like it does a good job parsing dates, but doesn't seem to do
english dates. I found a javascript implementation of a few functions
that will probably be relatively easy to port to python. Whether or
not it'll perform well is another story... Thanks for the help.
datetime.datetime(2003, 4, 16, 0, 0)

Aren't these "english dates"?

Michael
 
J

John McMonagle

datetime.datetime(2003, 4, 16, 0, 0)

Aren't these "english dates"?

I suspect the OP is referring to "english dates" as non-US format - to
follow the international convention (DD/MM/YYYY).

You can use the dayfirst parameter to the parse function to always
assume international date format:

US Format:datetime.datetime(2004, 10, 12, 0, 0)

International format:datetime.datetime(2004, 12, 10, 0, 0)


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top