src/English/timex/en_TemporalNormalizer.cpp
/* searches ts for dates in the form mm-dd or mm-dd-yyyy or mm-yyyy or
mm/dd or mm/dd/yyyy or mm/yyyy, etc. and returns a time object set to
contain the value of the first such date pattern found. */
searches ts for dates in the form mm-dd or mm-dd-yyyy or mm-yyyy or
mm/dd or mm/dd/yyyy or mm/yyyy, etc. and returns a time object set to
contain the value of the first such date pattern found.
searches ts for dates in the form mm - dd or mm - dd - yyyy or mm - yyyy or mm / dd or mm / dd / yyyy or mm / yyyy etc . and returns a time object set to contain the value of the first such date pattern found .
TimeObj* EnglishTemporalNormalizer::getAndParseDateString(TemporalString* ts) {
	TimeObj *result = new TimeObj();
	wstring delims[3] = { L"-", L"/", L"\\" };
	wstring m, d, y, rest, previous;
	for (int i = 0; i < 3; i++) {
		for (int j = 1; j < ts->size() - 1; j++) {   
			if (!ts->tokenAt(j).compare(delims[i])) {
				m = ts->tokenAt(j - 1);
				d = ts->tokenAt(j + 1);
				previous = ts->tokenAt(j - 2);
				if (Strings::parseInt(m) >= 1 && Strings::parseInt(m) <= 12 &&
					Strings::parseInt(d) >= 1 && Strings::parseInt(d) <= 31 &&
					previous.compare(L":"))
				{
					result->setTime(L"MM", m);
					result->setTime(L"DD", d);
					if (!ts->tokenAt(j+2).compare(delims[i])) {
						y = ts->tokenAt(j+3);
						if (Strings::parseInt(y) != -1) {
							result->setTime(L"YYYY", Year::canonicalizeYear(Strings::parseInt(y)));
							ts->remove(j-1, j+3);
							return result;
						}
					}
					ts->remove(j-1, j+1);
					return result;
				}
				else if (Strings::parseInt(m) >= 1 && Strings::parseInt(m) <= 12 && 
					     Strings::parseInt(d) > -1 && previous.compare(L":")) 
				{
					result->setTime(L"MM", m);
					result->setTime(L"YYYY", Year::canonicalizeYear(Strings::parseInt(d)));
					ts->remove(j-1, j+1);
					return result;
				}
				else if (Strings::parseInt(d) >= 1 && Strings::parseInt(d) <= 12 && 
					     Strings::parseInt(m) > -1 && previous.compare(L":")) 
				{
					result->setTime(L"MM", d);
					result->setTime(L"YYYY", Year::canonicalizeYear(Strings::parseInt(m)));
					ts->remove(j-1, j+1);
					return result;
				}
			}
		}
	}
	delete result;
	return NULL;
}
TimeObj * EnglishTemporalNormalizer :: getAndParseDateString ( TemporalString * ts ) { TimeObj * result = new TimeObj ( ) ; wstring delims [ 3 ] = { L" " , L" " , L" \\ " } ; wstring m , d , y , rest , previous ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 1 ; j < ts -> size ( ) - 1 ; j ++ ) { if ( ! ts -> tokenAt ( j ) . compare ( delims [ i ] ) ) { m = ts -> tokenAt ( j - 1 ) ; d = ts -> tokenAt ( j + 1 ) ; previous = ts -> tokenAt ( j - 2 ) ; if ( Strings :: parseInt ( m ) >= 1 && Strings :: parseInt ( m ) <= 12 && Strings :: parseInt ( d ) >= 1 && Strings :: parseInt ( d ) <= 31 && previous . compare ( L" " ) ) { result -> setTime ( L" " , m ) ; result -> setTime ( L" " , d ) ; if ( ! ts -> tokenAt ( j + 2 ) . compare ( delims [ i ] ) ) { y = ts -> tokenAt ( j + 3 ) ; if ( Strings :: parseInt ( y ) != -1 ) { result -> setTime ( L" " , Year :: canonicalizeYear ( Strings :: parseInt ( y ) ) ) ; ts -> remove ( j - 1 , j + 3 ) ; return result ; } } ts -> remove ( j - 1 , j + 1 ) ; return result ; } else if ( Strings :: parseInt ( m ) >= 1 && Strings :: parseInt ( m ) <= 12 && Strings :: parseInt ( d ) > -1 && previous . compare ( L" " ) ) { result -> setTime ( L" " , m ) ; result -> setTime ( L" " , Year :: canonicalizeYear ( Strings :: parseInt ( d ) ) ) ; ts -> remove ( j - 1 , j + 1 ) ; return result ; } else if ( Strings :: parseInt ( d ) >= 1 && Strings :: parseInt ( d ) <= 12 && Strings :: parseInt ( m ) > -1 && previous . compare ( L" " ) ) { result -> setTime ( L" " , d ) ; result -> setTime ( L" " , Year :: canonicalizeYear ( Strings :: parseInt ( m ) ) ) ; ts -> remove ( j - 1 , j + 1 ) ; return result ; } } } } delete result ; return NULL ; }
searches ts for dates in the form mm-dd or mm-dd-yyyy or mm-yyyy or
mm/dd or mm/dd/yyyy or mm/yyyy, etc.
searches ts for dates in the form mm - dd or mm - dd - yyyy or mm - yyyy or mm / dd or mm / dd / yyyy or mm / yyyy etc .
// 20040912
 /*	for (int i = 0; i < ts->size(); i++) {
		wstring date = ts->tokenAt(i);
		
		if (date.length() == 8 && Strings::parseInt(date) > -1) {
			wstring year = date.substr(0, 4);
			wstring month = date.substr(4, 2);
			wstring day = date.substr(6, 2);
			if (Strings::parseInt(month) >= 1 && Strings::parseInt(month) <= 12 &&
				Strings::parseInt(day) >= 1 && Strings::parseInt(day) <= 31)
			{
				result->setTime(L"YYYY", year);
				result->setTime(L"MM", month);
				result->setTime(L"DD", day);
				ts->remove(i);
				return result;
			}	
		}
	}*/ // search through i - (ts.size()-1)
