13

I'm building a system that needs to provide a commentary on things in natural English. One thing that is of use is to be able to express dates in a casual format. What I'm looking for is essentially the inverse of Chronic, Natty, or the task described in this question: Natural Language date and time parser for java.

Is this too out-there to have been done? Should I try and roll my own simple hardwired piece for the date ranges that make sense to me? Or is there some clever way to reverse existing parsers to spit out (even garbled) sentences describing dates?

EDIT - To clarify, although any kind of output is interesting and useful, I'm particularly interested in varied/creative output generation. i.e. "Next week", "seven days from now", "next Thursday" and "late next week" all for the same date.

Community
  • 1
  • 1
mtrc
  • 1,317
  • 3
  • 16
  • 39
  • 4
    They definitely exist, ie [javascript](https://github.com/timrwood/moment). I can't recall any for java offhand though. – Andrew May 02 '12 at 18:46
  • 1
    I don't quite understand what you are asking, but it seems you want to generate "Wednesday, two of May of two thousand and twelve"(~) out of "05/02/2012"(~), is it correct? If so, it is not too hard to code a function that will give you the desired output(s). See java's DateFormat class: http://docs.oracle.com/javase/6/docs/api/java/text/DateFormat.html – CosmicGiant May 02 '12 at 19:18
  • @TheLima I think it's more he wants, `05/03/2012` -> `tomorrow` or `05/07/2012` -> `next monday` – Andrew May 02 '12 at 19:23
  • @Andrew Well, then i'm close to saying it is, at best, unpractical, for such API/Library to exist. (Tough it is VERY possible to code it)...If a single function was to generate the same outputs as my example's, your's and/or other different outputs, it would (i think) require a painfully exact input to a regex-like parameter, or an even worse, largely parametric structure. – CosmicGiant May 02 '12 at 20:03
  • I agree. I actually work in computational creativity, where we look at issues surrounding this - we don't want everyone to write the same way. Which was kind of the core of my question, are there systems that produce interesting and varied natural language along these lines? Which I suppose is asking a lot! – mtrc May 03 '12 at 15:51
  • Something like `parseDate` in `Date d = parseDate("This Tuesday", currentDate, TenseBias.PROBABLY_FUTURE);` – Mike Samuel May 03 '12 at 15:56
  • JGoodies validation has a RelativeDateFormatter class. It's pretty limited and it's only able to print yesterday,today and tomorrow, but may be a good starting point... – Andrea Parodi May 03 '12 at 16:06
  • Sounds interesting, thanks! I"ll check them out. I'm also quite keen on @Andrew's link, I might try hook that into my Java program via Rhino or somesuch, as a static solution. Keep them coming! – mtrc May 03 '12 at 16:08
  • Just wanted to let everyone know I'm still looking to check these out, haven't found the time yet! – mtrc May 06 '12 at 18:25
  • Did you ever check these out? – dsummersl Jun 14 '13 at 02:42

1 Answers1

5

There isn't much out there. Personally I'd love to see a variant of SimpleDateFormatter called RelativeDateFormatter that would let one create their own variations of relative date formats. Here is what I found:

Just an aside, I noticed this post about why relative date formats suck. Providing only relative dates can be a mistake: if the information is going to be saved at a later date, the relative date could be useless. In a website I made I provided a mouseover with the absolute date, and CSS rules to print the absolute date. I guess the thing to keep in mind: consider how/when the dates will be viewed. If they're anything other than "NOW" then you might want to consider including the absolute date as well.

dsummersl
  • 6,588
  • 50
  • 65
  • I do like Pretty Time, that looks nice. I'm going to look at both that and Andrew's suggestion of 'moment' at the earliest opportunity. I'll get back to you then! – mtrc May 03 '12 at 22:17