private boolean findDate ( String [ ] strs , int tolerance ) { dfirst = - 1 ; dlast = - 1 ; int curend = - 1 ; int intpos = - 1 ; //interesting position found (not a simple number) for ( int i = 0 ; i < strs . length ; i ++ ) { if ( isMonthName ( strs [ i ] ) || isYear ( strs [ i ] ) ) intpos = i ; if ( intpos == i || isNum ( strs [ i ] ) ) { if ( isYear ( strs [ i ] ) ) intpos = i ; if ( curend == - 1 ) curend = i ; else { if ( i - curend <= tolerance ) //extending the group curend = i ; else //cannot extend the group { if ( dlast - dfirst >= 1 && intpos >= dfirst && intpos <= dlast ) //suitable group found return true ; else //no suitable group, try the next one { curend = i ; dfirst = i ; dlast = i ; } } } if ( dfirst == - 1 ) dfirst = curend ; dlast = curend ; } } return ( dlast - dfirst >= 1 ) ; }
Searches for sequences like num month or month num or num year in the string . If the date is found the dfirst and dlast properties are set to the indices of the first and last index of the corresponding words .