Natural Language Date Processing.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Gwozdziewycz

    #1

    Natural Language Date Processing.

    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
    apgwoz@gmail.co m




  • andychambers2002@yahoo.co.uk

    #2
    Re: Natural Language Date Processing.

    >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

    Comment

    • Andrew Gwozdziewycz

      #3
      Re: Natural Language Date Processing.

      On 7 Feb 2006 05:51:40 -0800, andychambers200 2@yahoo.co.uk[color=blue]
      > 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.[/color]

      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.


      --
      Andrew Gwozdziewycz <apgwoz@gmail.c om>


      Comment

      • Steven Bethard

        #4
        Re: Natural Language Date Processing.

        Andrew Gwozdziewycz wrote:[color=blue]
        > 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".[/color]

        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:



        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

        Comment

        • Michael Amrhein

          #5
          Re: Natural Language Date Processing.

          Andrew Gwozdziewycz schrieb:[color=blue]
          > 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
          > apgwoz@gmail.co m
          > http://ihadagreatview.org
          > http://plasticandroid.org
          >
          >[/color]

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

          Comment

          • Michael Amrhein

            #6
            Re: Natural Language Date Processing.

            Andrew Gwozdziewycz schrieb:[color=blue]
            > 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
            > apgwoz@gmail.co m
            > http://ihadagreatview.org
            > http://plasticandroid.org
            >
            >[/color]

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

            Comment

            • Andrew Gwozdziewycz

              #7
              Re: Natural Language Date Processing.

              > You may take a look at http://labix.org/python-dateutil[color=blue]
              > Have fun
              > Michael
              >[/color]

              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.

              --
              Andrew Gwozdziewycz <apgwoz@gmail.c om>


              Comment

              • Michael Amrhein

                #8
                Re: Natural Language Date Processing.

                Andrew Gwozdziewycz schrieb:[color=blue][color=green]
                >> You may take a look at http://labix.org/python-dateutil
                >> Have fun
                >> Michael
                >>[/color]
                >
                > 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.
                >
                > --
                > Andrew Gwozdziewycz <apgwoz@gmail.c om>
                > http://ihadagreatview.org
                > http://plasticandroid.org[/color]
                [color=blue][color=green][color=darkred]
                >>>from dateutil.parser import parse
                >>>parse("Apr il 16th, 2003")[/color][/color][/color]
                datetime.dateti me(2003, 4, 16, 0, 0)[color=blue][color=green][color=darkred]
                >>>parse("4/16/2003")[/color][/color][/color]
                datetime.dateti me(2003, 4, 16, 0, 0)

                Aren't these "english dates"?

                Michael

                Comment

                • Michael Amrhein

                  #9
                  Re: Natural Language Date Processing.

                  Andrew Gwozdziewycz schrieb:[color=blue][color=green]
                  >> You may take a look at http://labix.org/python-dateutil
                  >> Have fun
                  >> Michael
                  >>[/color]
                  >
                  > 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.
                  >
                  > --
                  > Andrew Gwozdziewycz <apgwoz@gmail.c om>
                  > http://ihadagreatview.org
                  > http://plasticandroid.org[/color]
                  [color=blue][color=green][color=darkred]
                  >>>from dateutil.parser import parse
                  >>>parse("Apr il 16th, 2003")[/color][/color][/color]
                  datetime.dateti me(2003, 4, 16, 0, 0)[color=blue][color=green][color=darkred]
                  >>>parse("4/16/2003")[/color][/color][/color]
                  datetime.dateti me(2003, 4, 16, 0, 0)

                  Aren't these "english dates"?

                  Michael

                  Comment

                  • John McMonagle

                    #10
                    Re: Natural Language Date Processing.

                    On Thu, 2006-02-09 at 09:47 +0100, Michael Amrhein wrote:[color=blue]
                    > Andrew Gwozdziewycz schrieb:[color=green][color=darkred]
                    > >> You may take a look at http://labix.org/python-dateutil
                    > >> Have fun
                    > >> Michael
                    > >>[/color]
                    > >
                    > > 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.
                    > >
                    > > --
                    > > Andrew Gwozdziewycz <apgwoz@gmail.c om>
                    > > http://ihadagreatview.org
                    > > http://plasticandroid.org[/color]
                    >[color=green][color=darkred]
                    > >>>from dateutil.parser import parse
                    > >>>parse("Apr il 16th, 2003")[/color][/color]
                    > datetime.dateti me(2003, 4, 16, 0, 0)[color=green][color=darkred]
                    > >>>parse("4/16/2003")[/color][/color]
                    > datetime.dateti me(2003, 4, 16, 0, 0)
                    >
                    > Aren't these "english dates"?[/color]

                    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:[color=blue][color=green][color=darkred]
                    >>> parse("10/12/2004")[/color][/color][/color]
                    datetime.dateti me(2004, 10, 12, 0, 0)

                    International format:[color=blue][color=green][color=darkred]
                    >>> parse("10/12/2004", dayfirst=True)[/color][/color][/color]
                    datetime.dateti me(2004, 12, 10, 0, 0)


                    John




                    --
                    This message has been scanned for viruses and
                    dangerous content by MailScanner, and is
                    believed to be clean.

                    Comment

                    Working...