leila.parsing
Class DateParser

java.lang.Object
  extended by leila.parsing.DateParser

public class DateParser
extends java.lang.Object

This class is part of LEILA (http://mpii.de/yago-naga/leila). It is licensed under the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0) by the author Fabian M. Suchanek (http://suchanek.name).

The DateParser normalizes date expressions in english natural language text to expressions of the form

@year_month_day@

where year is either positive negative. The DateParser understands expressions like "4th century BC" or "3rd of November 2004". Dates may be underspecified: The character '#' stands for "at least one digit". A match-function is provided that checks if two potentially underspecified dates or year numbers match. Every positive normalized integer number is a date (namely a year).
Example:
         DateParser.normalize("It was November 23rd to 24th 1998.")
         --> "It was @1998_11_23@ to @1998_11_24@."
         NumberFormatter.ISOtime(DateParser.getCalendar("November 24th 1998"))
         --> 1998-12-24 T 00:00:00.00
   


Field Summary
static java.lang.String ANYDATE
          The general default date
static java.lang.String DATE
          A Date as a capturing RegEx
static java.util.regex.Pattern DATEPATTERN
           
 
Constructor Summary
DateParser()
           
 
Method Summary
static java.util.Calendar getCalendar(java.lang.String s)
          Converts a String to a Calendar
static java.lang.String getDay(java.lang.String d)
          Extracts the day as a String
static java.lang.String getMonth(java.lang.String d)
          Extracts the month as a String
static java.lang.String getYear(java.lang.String d)
          Extracts the year as a String
static boolean isDate(java.lang.String s)
          Tells whether this string is a normalized date (or year number)
static void main(java.lang.String[] argv)
          Test routine
static boolean match(java.lang.String d1, java.lang.String d2)
          Tells whether two date-strings match Also matches normalized positive year numbers with other positive year numbers or dates
static java.lang.String newDate(int d, int m, int y)
          Creates a date-string from a day, month and year as ints
static java.lang.String newDate(java.lang.String d, java.lang.String m, java.lang.String y)
          Creates a date-string of the form @year_month_day@ from a day, month and year
static java.lang.String normalize(java.lang.String s)
          Normalizes all dates in a String Convenience method for the more efficient StringBuilder-method
static java.lang.StringBuilder normalize(java.lang.StringBuilder s)
          Normalizes all dates in a StringBuilder, may mess up the original StringBuilder
static int toInt(java.lang.String s)
          Converts a String to an integer or 0 in case of failure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANYDATE

public static final java.lang.String ANYDATE
The general default date


DATE

public static final java.lang.String DATE
A Date as a capturing RegEx


DATEPATTERN

public static final java.util.regex.Pattern DATEPATTERN
Constructor Detail

DateParser

public DateParser()
Method Detail

newDate

public static final java.lang.String newDate(java.lang.String d,
                                             java.lang.String m,
                                             java.lang.String y)
Creates a date-string of the form @year_month_day@ from a day, month and year


newDate

public static final java.lang.String newDate(int d,
                                             int m,
                                             int y)
Creates a date-string from a day, month and year as ints


normalize

public static java.lang.StringBuilder normalize(java.lang.StringBuilder s)
Normalizes all dates in a StringBuilder, may mess up the original StringBuilder


normalize

public static java.lang.String normalize(java.lang.String s)
Normalizes all dates in a String Convenience method for the more efficient StringBuilder-method


isDate

public static boolean isDate(java.lang.String s)
Tells whether this string is a normalized date (or year number)


match

public static boolean match(java.lang.String d1,
                            java.lang.String d2)
Tells whether two date-strings match Also matches normalized positive year numbers with other positive year numbers or dates


getYear

public static java.lang.String getYear(java.lang.String d)
Extracts the year as a String


getMonth

public static java.lang.String getMonth(java.lang.String d)
Extracts the month as a String


getDay

public static java.lang.String getDay(java.lang.String d)
Extracts the day as a String


toInt

public static int toInt(java.lang.String s)
Converts a String to an integer or 0 in case of failure


getCalendar

public static java.util.Calendar getCalendar(java.lang.String s)
Converts a String to a Calendar


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Test routine

Throws:
java.lang.Exception