Java Date and Time Natural Language Parsing NLP

PrettyTime :: NLP

The simplest, smallest natural language java.util.Date and human time parsing library for Java: Computers understanding people.

1. Include PrettyTime :: NLP in your Project

Add PrettyTime :: NLP to your maven pom.xmlOr download the JARs

<!-- To use snapshots, you must also use the Sonatype Snapshots respository -->

2. Use PrettyTimeParser

PrettyTime NLP is simple, and requires interfacing with only a single class, PrettyTimeParser
Parse your first natural date
package com.example;

import org.ocpsoft.prettytime.nlp.PrettyTimeParser;

public class Example
   public static void main(String[] args)
      List<Date> dates = new PrettyTimeParser().parse("I'm going to the beach in three days!");
      // Prints: "[Sun Dec 12 13:45:12 CET 2013]"

3. Get more detailed.

You can also get more detailed results from the text, including whether or not dates are recurring, and when they recur until:

Parse recurring dates
   public void testParseSyntaxRecurring()
      List<DateGroup> parse = new PrettyTimeParser().parseSyntax("I eat fish every three days");
      String formatted = new PrettyTime().format(parse.get(0).getDates().get(0));
      Assert.assertEquals("3 days from now", formatted);
      Assert.assertEquals(1, parse.get(0).getLine());
      Assert.assertEquals(14, parse.get(0).getPosition());
      Assert.assertEquals(1, parse.get(0).getDates().size());
      Assert.assertEquals(1000 * 60 * 60 * 24 * 3, parse.get(0).getRecurInterval());