Alex Rivera | Logout

Natural Language parsing of an appointment?

Asked 2010-04-06T19:26:35.227
13

I'm looking for a Java library to help parse user entered text that represents an 'appointment' for a calendar application. For instance:

Lunch with Mike at 11:30 on Tuesday

or

5pm Happy hour on Friday

I've found some promising leads like https://github.com/samtingleff/jchronic and http://www.datejs.com/ which can parse dates - but I also need to be able to extract the title of the event like "Lunch with Mike".

If such an API doesn't exist, I'm also interested in any thoughts on how best to approach the problem from a coding perspective.

Edit
Report

1 Answer

10

Extending JChronic may be your best bet. I think, given the responses to this question, it's unlikely that a pre-built library for this exists (though it seems like such a thing could be useful... I'm guessing that the major use-cases for parsing natural language dates would be even more useful if they had the ability to extract additional data from user-supplied strings).

Implementation-wise, probably the most straight-forward thing to do is to extend JChronic, since, it supports quite a significant part of your use-case, but more over as you can see from the unit test extraneous information should already be ignored by the framework. Fortunately, too, if you look at the main class, it should not be too hard to extend / modify / wrap the parse() method to support a custom scanner for an event title. (My own preference of these would be to wrap the framework rather than fork and modify it, as that allows you to benefit from any improvements to the underlying code more easily).

Ultimately, what may prove the most straight-forward way of doing this is to generate a regex-parser that ignores most of what JChronic tries to capture (and this would mean becoming deeply familiar with the JChronic source code).

The key to successfully implementing this, as with any NLP-type project is to have as many examples as you can possibly get, preferrably as automated unit tests (ultimately, even if the test cases test duplicate the same functionality many times, it is better to have more examples than fewer). Fortunately, since we're talking about natural language, such test cases should be

answered 2010-04-07T01:25:11.420

Your Answer