private void findIntervals(JCas jcas) {
		ArrayList<Timex3Interval> newAnnotations = new ArrayList<Timex3Interval>();
		
		FSIterator iterTimex3 = jcas.getAnnotationIndex(Timex3.type).iterator();
		while (iterTimex3.hasNext()) {
			Timex3Interval annotation=new Timex3Interval(jcas);
			Timex3 timex3 = (Timex3) iterTimex3.next();
			
			//DATE Pattern
			Pattern pDate = Pattern.compile("(?:BC)?(\\d\\d\\d\\d)(-(\\d+))?(-(\\d+))?(T(\\d+))?(:(\\d+))?(:(\\d+))?");
			Pattern pCentury = Pattern.compile("(\\d\\d)");
			Pattern pDecate = Pattern.compile("(\\d\\d\\d)");
			Pattern pQuarter = Pattern.compile("(\\d+)-Q([1-4])");
			Pattern pHalf = Pattern.compile("(\\d+)-H([1-2])");
			Pattern pSeason = Pattern.compile("(\\d+)-(SP|SU|FA|WI)");
			Pattern pWeek = Pattern.compile("(\\d+)-W(\\d+)");
			Pattern pWeekend = Pattern.compile("(\\d+)-W(\\d+)-WE");
			Pattern pTimeOfDay = Pattern.compile("(\\d+)-(\\d+)-(\\d+)T(AF|DT|MI|MO|EV|NI)");
			
			Matcher mDate   = pDate.matcher(timex3.getTimexValue());
			Matcher mCentury= pCentury.matcher(timex3.getTimexValue());
			Matcher mDecade = pDecate.matcher(timex3.getTimexValue());
			Matcher mQuarter= pQuarter.matcher(timex3.getTimexValue());
			Matcher mHalf   = pHalf.matcher(timex3.getTimexValue());
			Matcher mSeason = pSeason.matcher(timex3.getTimexValue());
			Matcher mWeek   = pWeek.matcher(timex3.getTimexValue());
			Matcher mWeekend= pWeekend.matcher(timex3.getTimexValue());
			Matcher mTimeOfDay= pTimeOfDay.matcher(timex3.getTimexValue());
			
			boolean matchesDate=mDate.matches();
			boolean matchesCentury=mCentury.matches();
			boolean matchesDecade=mDecade.matches();
			boolean matchesQuarter=mQuarter.matches();
			boolean matchesHalf=mHalf.matches();
			boolean matchesSeason=mSeason.matches();
			boolean matchesWeek=mWeek.matches();
			boolean matchesWeekend=mWeekend.matches();
			boolean matchesTimeOfDay=mTimeOfDay.matches();
			
			String beginYear, endYear;
			String beginMonth, endMonth;
			String beginDay, endDay;
			String beginHour, endHour;
			String beginMinute, endMinute;
			String beginSecond, endSecond;

			beginYear=endYear="UNDEF";
			beginMonth="01";
			endMonth="12";
			beginDay="01";
			endDay="31";
			beginHour="00";
			endHour="23";
			beginMinute="00";
			endMinute="59";
			beginSecond="00";
			endSecond="59";
			
			if(matchesDate){
				
				//Get Year(1)
				beginYear=endYear=mDate.group(1);
				
				//Get Month(3)
				if(mDate.group(3)!=null){
					beginMonth=endMonth=mDate.group(3);
					
					//Get Day(5)
					if(mDate.group(5)==null){
						Calendar c=Calendar.getInstance();
						c.set(Integer.parseInt(beginYear), Integer.parseInt(beginMonth)-1, 1);
						endDay=""+c.getActualMaximum(Calendar.DAY_OF_MONTH);
						beginDay="01";
					}else{
						beginDay=endDay=mDate.group(5);
						
						//Get Hour(7)
						if(mDate.group(7)!=null){
							beginHour=endHour=mDate.group(7);

							//Get Minute(9)
							if(mDate.group(9)!=null){
								beginMinute=endMinute=mDate.group(9);

								//Get Second(11)
								if(mDate.group(11)!=null){
									beginSecond=endSecond=mDate.group(11);
								}
							}
						}
						
					}
				}
				
			}else if(matchesCentury){
				beginYear=mCentury.group(1)+"00";
				endYear=mCentury.group(1)+"99";
			}else if(matchesDecade){
				beginYear=mDecade.group(1)+"0";
				endYear=mDecade.group(1)+"9";
			}else if(matchesQuarter){
				beginYear=endYear=mQuarter.group(1);
				int beginMonthI=3*(Integer.parseInt(mQuarter.group(2))-1)+1;
				beginMonth=""+beginMonthI;
				endMonth=""+(beginMonthI+2);
				Calendar c=Calendar.getInstance();
				c.set(Integer.parseInt(beginYear), Integer.parseInt(endMonth)-1, 1);
				endDay=""+c.getActualMaximum(Calendar.DAY_OF_MONTH);
			}else if(matchesHalf){
				beginYear=endYear=mHalf.group(1);
				int beginMonthI=6*(Integer.parseInt(mHalf.group(2))-1)+1;
				beginMonth=""+beginMonthI;
				endMonth=""+(beginMonthI+5);
				Calendar c=Calendar.getInstance();
				c.set(Integer.parseInt(beginYear), Integer.parseInt(endMonth)-1, 1);
				endDay=""+c.getActualMaximum(Calendar.DAY_OF_MONTH);
			}else if(matchesSeason){
				beginYear=mSeason.group(1);
				endYear=beginYear;
				if(mSeason.group(2).equals("SP")){
					beginMonth="03";
					beginDay="21";
					endMonth="06";
					endDay="20";
				}else if(mSeason.group(2).equals("SU")){
					beginMonth="06";
					beginDay="21";
					endMonth="09";
					endDay="22";
				}else if(mSeason.group(2).equals("FA")){
					beginMonth="09";
					beginDay="23";
					endMonth="12";
					endDay="21";
				}else if(mSeason.group(2).equals("WI")){
					endYear=""+(Integer.parseInt(beginYear)+1);
					beginMonth="12";
					beginDay="22";
					endMonth="03";
					endDay="20";
				}
			}else if(matchesWeek){
				beginYear=endYear=mWeek.group(1);
				Calendar c=Calendar.getInstance();
				c.setFirstDayOfWeek(Calendar.MONDAY);
				c.set(Calendar.YEAR,Integer.parseInt(beginYear));
				c.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(mWeek.group(2)));
				c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
				beginDay=""+c.get(Calendar.DAY_OF_MONTH);
				beginMonth=""+(c.get(Calendar.MONTH)+1);
				c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
				endDay=""+(c.get(Calendar.DAY_OF_MONTH));
				endMonth=""+(c.get(Calendar.MONTH)+1);
			}else if(matchesWeekend){
				beginYear=endYear=mWeekend.group(1);
				Calendar c=Calendar.getInstance();
				c.setFirstDayOfWeek(Calendar.MONDAY);
				c.set(Calendar.YEAR,Integer.parseInt(beginYear));
				c.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(mWeekend.group(2)));
				c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
				beginDay=""+c.get(Calendar.DAY_OF_MONTH);
				beginMonth=""+(c.get(Calendar.MONTH)+1);
				c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
				endDay=""+(c.get(Calendar.DAY_OF_MONTH));
				endMonth=""+(c.get(Calendar.MONTH)+1);
			}else if(matchesTimeOfDay){
				beginYear=endYear=mTimeOfDay.group(1);
				beginMonth=endMonth=mTimeOfDay.group(2);
				beginDay=endDay=mTimeOfDay.group(3);
			}
			
			// correct month and days < 10
			if (Integer.parseInt(beginDay) < 10){
				beginDay = "0" + Integer.parseInt(beginDay);
			}
			if (Integer.parseInt(beginMonth) < 10){
				beginMonth = "0" + Integer.parseInt(beginMonth);
			}
			if (Integer.parseInt(endDay) < 10){
				endDay = "0" + Integer.parseInt(endDay);
			}
			if (Integer.parseInt(endMonth) < 10){
				endMonth = "0" + Integer.parseInt(endMonth);
			}
			
			if(!beginYear.equals("UNDEF") && !endYear.equals("UNDEF")){
				annotation.setTimexValueEB(beginYear+"-"+beginMonth+"-"+beginDay+"T"+beginHour+":"+beginMinute+":"+beginSecond);
//				annotation.setTimexValueLB(beginYear+"-"+beginMonth+"-"+beginDay+"T"+endHour+":"+endMinute+":"+endSecond);
//				annotation.setTimexValueEE(endYear+"-"+endMonth+"-"+endDay+"T"+beginHour+":"+beginMinute+":"+beginSecond);
				annotation.setTimexValueLE(endYear+"-"+endMonth+"-"+endDay+"T"+endHour+":"+endMinute+":"+endSecond);
				annotation.setTimexValueLB(endYear+"-"+endMonth+"-"+endDay+"T"+endHour+":"+endMinute+":"+endSecond);
				annotation.setTimexValueEE(beginYear+"-"+beginMonth+"-"+beginDay+"T"+beginHour+":"+beginMinute+":"+beginSecond);
				
				//Copy Values from the Timex3 Annotation
				annotation.setTimexFreq(timex3.getTimexFreq());
				annotation.setTimexId(timex3.getTimexId());
				annotation.setTimexInstance(timex3.getTimexInstance());
				annotation.setTimexMod(timex3.getTimexMod());
				annotation.setTimexQuant(timex3.getTimexMod());
				annotation.setTimexType(timex3.getTimexType());
				annotation.setTimexValue(timex3.getTimexValue());
				annotation.setSentId(timex3.getSentId());
				annotation.setBegin(timex3.getBegin());
				annotation.setFoundByRule(timex3.getFoundByRule());
				annotation.setEnd(timex3.getEnd());
				annotation.setAllTokIds(timex3.getAllTokIds());
				annotation.setFilename(timex3.getFilename());
				annotation.setBeginTimex(timex3.getTimexId());
				annotation.setEndTimex(timex3.getTimexId());
				
				// remember this one for addition to indexes later
				newAnnotations.add(annotation);
			}
		}
		// add to indexes
		for(Timex3Interval t3i : newAnnotations)
			t3i.addToIndexes();
	}
private void findIntervals ( JCas jcas ) { ArrayList < Timex3Interval > newAnnotations = new ArrayList < Timex3Interval > ( ) ; FSIterator iterTimex3 = jcas . getAnnotationIndex ( Timex3 . type ) . iterator ( ) ; while ( iterTimex3 . hasNext ( ) ) { Timex3Interval annotation = new Timex3Interval ( jcas ) ; Timex3 timex3 = ( Timex3 ) iterTimex3 . next ( ) ; Pattern pDate = Pattern . compile ( "(?:BC)?(\\d\\d\\d\\d)(-(\\d+))?(-(\\d+))?(T(\\d+))?(:(\\d+))?(:(\\d+))?" ) ; Pattern pCentury = Pattern . compile ( "(\\d\\d)" ) ; Pattern pDecate = Pattern . compile ( "(\\d\\d\\d)" ) ; Pattern pQuarter = Pattern . compile ( "(\\d+)-Q([1-4])" ) ; Pattern pHalf = Pattern . compile ( "(\\d+)-H([1-2])" ) ; Pattern pSeason = Pattern . compile ( "(\\d+)-(SP|SU|FA|WI)" ) ; Pattern pWeek = Pattern . compile ( "(\\d+)-W(\\d+)" ) ; Pattern pWeekend = Pattern . compile ( "(\\d+)-W(\\d+)-WE" ) ; Pattern pTimeOfDay = Pattern . compile ( "(\\d+)-(\\d+)-(\\d+)T(AF|DT|MI|MO|EV|NI)" ) ; Matcher mDate = pDate . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mCentury = pCentury . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mDecade = pDecate . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mQuarter = pQuarter . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mHalf = pHalf . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mSeason = pSeason . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mWeek = pWeek . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mWeekend = pWeekend . matcher ( timex3 . getTimexValue ( ) ) ; Matcher mTimeOfDay = pTimeOfDay . matcher ( timex3 . getTimexValue ( ) ) ; boolean matchesDate = mDate . matches ( ) ; boolean matchesCentury = mCentury . matches ( ) ; boolean matchesDecade = mDecade . matches ( ) ; boolean matchesQuarter = mQuarter . matches ( ) ; boolean matchesHalf = mHalf . matches ( ) ; boolean matchesSeason = mSeason . matches ( ) ; boolean matchesWeek = mWeek . matches ( ) ; boolean matchesWeekend = mWeekend . matches ( ) ; boolean matchesTimeOfDay = mTimeOfDay . matches ( ) ; String beginYear , endYear ; String beginMonth , endMonth ; String beginDay , endDay ; String beginHour , endHour ; String beginMinute , endMinute ; String beginSecond , endSecond ; beginYear = endYear = "UNDEF" ; beginMonth = "01" ; endMonth = "12" ; beginDay = "01" ; endDay = "31" ; beginHour = "00" ; endHour = "23" ; beginMinute = "00" ; endMinute = "59" ; beginSecond = "00" ; endSecond = "59" ; if ( matchesDate ) { beginYear = endYear = mDate . group ( 1 ) ; if ( mDate . group ( 3 ) != null ) { beginMonth = endMonth = mDate . group ( 3 ) ; if ( mDate . group ( 5 ) == null ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Integer . parseInt ( beginYear ) , Integer . parseInt ( beginMonth ) - 1 , 1 ) ; endDay = "" + c . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; beginDay = "01" ; } else { beginDay = endDay = mDate . group ( 5 ) ; if ( mDate . group ( 7 ) != null ) { beginHour = endHour = mDate . group ( 7 ) ; if ( mDate . group ( 9 ) != null ) { beginMinute = endMinute = mDate . group ( 9 ) ; if ( mDate . group ( 11 ) != null ) { beginSecond = endSecond = mDate . group ( 11 ) ; } } } } } } else if ( matchesCentury ) { beginYear = mCentury . group ( 1 ) + "00" ; endYear = mCentury . group ( 1 ) + "99" ; } else if ( matchesDecade ) { beginYear = mDecade . group ( 1 ) + "0" ; endYear = mDecade . group ( 1 ) + "9" ; } else if ( matchesQuarter ) { beginYear = endYear = mQuarter . group ( 1 ) ; int beginMonthI = 3 * ( Integer . parseInt ( mQuarter . group ( 2 ) ) - 1 ) + 1 ; beginMonth = "" + beginMonthI ; endMonth = "" + ( beginMonthI + 2 ) ; Calendar c = Calendar . getInstance ( ) ; c . set ( Integer . parseInt ( beginYear ) , Integer . parseInt ( endMonth ) - 1 , 1 ) ; endDay = "" + c . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; } else if ( matchesHalf ) { beginYear = endYear = mHalf . group ( 1 ) ; int beginMonthI = 6 * ( Integer . parseInt ( mHalf . group ( 2 ) ) - 1 ) + 1 ; beginMonth = "" + beginMonthI ; endMonth = "" + ( beginMonthI + 5 ) ; Calendar c = Calendar . getInstance ( ) ; c . set ( Integer . parseInt ( beginYear ) , Integer . parseInt ( endMonth ) - 1 , 1 ) ; endDay = "" + c . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; } else if ( matchesSeason ) { beginYear = mSeason . group ( 1 ) ; endYear = beginYear ; if ( mSeason . group ( 2 ) . equals ( "SP" ) ) { beginMonth = "03" ; beginDay = "21" ; endMonth = "06" ; endDay = "20" ; } else if ( mSeason . group ( 2 ) . equals ( "SU" ) ) { beginMonth = "06" ; beginDay = "21" ; endMonth = "09" ; endDay = "22" ; } else if ( mSeason . group ( 2 ) . equals ( "FA" ) ) { beginMonth = "09" ; beginDay = "23" ; endMonth = "12" ; endDay = "21" ; } else if ( mSeason . group ( 2 ) . equals ( "WI" ) ) { endYear = "" + ( Integer . parseInt ( beginYear ) + 1 ) ; beginMonth = "12" ; beginDay = "22" ; endMonth = "03" ; endDay = "20" ; } } else if ( matchesWeek ) { beginYear = endYear = mWeek . group ( 1 ) ; Calendar c = Calendar . getInstance ( ) ; c . setFirstDayOfWeek ( Calendar . MONDAY ) ; c . set ( Calendar . YEAR , Integer . parseInt ( beginYear ) ) ; c . set ( Calendar . WEEK_OF_YEAR , Integer . parseInt ( mWeek . group ( 2 ) ) ) ; c . set ( Calendar . DAY_OF_WEEK , Calendar . MONDAY ) ; beginDay = "" + c . get ( Calendar . DAY_OF_MONTH ) ; beginMonth = "" + ( c . get ( Calendar . MONTH ) + 1 ) ; c . set ( Calendar . DAY_OF_WEEK , Calendar . SUNDAY ) ; endDay = "" + ( c . get ( Calendar . DAY_OF_MONTH ) ) ; endMonth = "" + ( c . get ( Calendar . MONTH ) + 1 ) ; } else if ( matchesWeekend ) { beginYear = endYear = mWeekend . group ( 1 ) ; Calendar c = Calendar . getInstance ( ) ; c . setFirstDayOfWeek ( Calendar . MONDAY ) ; c . set ( Calendar . YEAR , Integer . parseInt ( beginYear ) ) ; c . set ( Calendar . WEEK_OF_YEAR , Integer . parseInt ( mWeekend . group ( 2 ) ) ) ; c . set ( Calendar . DAY_OF_WEEK , Calendar . SATURDAY ) ; beginDay = "" + c . get ( Calendar . DAY_OF_MONTH ) ; beginMonth = "" + ( c . get ( Calendar . MONTH ) + 1 ) ; c . set ( Calendar . DAY_OF_WEEK , Calendar . SUNDAY ) ; endDay = "" + ( c . get ( Calendar . DAY_OF_MONTH ) ) ; endMonth = "" + ( c . get ( Calendar . MONTH ) + 1 ) ; } else if ( matchesTimeOfDay ) { beginYear = endYear = mTimeOfDay . group ( 1 ) ; beginMonth = endMonth = mTimeOfDay . group ( 2 ) ; beginDay = endDay = mTimeOfDay . group ( 3 ) ; } if ( Integer . parseInt ( beginDay ) < 10 ) { beginDay = "0" + Integer . parseInt ( beginDay ) ; } if ( Integer . parseInt ( beginMonth ) < 10 ) { beginMonth = "0" + Integer . parseInt ( beginMonth ) ; } if ( Integer . parseInt ( endDay ) < 10 ) { endDay = "0" + Integer . parseInt ( endDay ) ; } if ( Integer . parseInt ( endMonth ) < 10 ) { endMonth = "0" + Integer . parseInt ( endMonth ) ; } if ( ! beginYear . equals ( "UNDEF" ) && ! endYear . equals ( "UNDEF" ) ) { annotation . setTimexValueEB ( beginYear + "-" + beginMonth + "-" + beginDay + "T" + beginHour + ":" + beginMinute + ":" + beginSecond ) ; annotation . setTimexValueLE ( endYear + "-" + endMonth + "-" + endDay + "T" + endHour + ":" + endMinute + ":" + endSecond ) ; annotation . setTimexValueLB ( endYear + "-" + endMonth + "-" + endDay + "T" + endHour + ":" + endMinute + ":" + endSecond ) ; annotation . setTimexValueEE ( beginYear + "-" + beginMonth + "-" + beginDay + "T" + beginHour + ":" + beginMinute + ":" + beginSecond ) ; annotation . setTimexFreq ( timex3 . getTimexFreq ( ) ) ; annotation . setTimexId ( timex3 . getTimexId ( ) ) ; annotation . setTimexInstance ( timex3 . getTimexInstance ( ) ) ; annotation . setTimexMod ( timex3 . getTimexMod ( ) ) ; annotation . setTimexQuant ( timex3 . getTimexMod ( ) ) ; annotation . setTimexType ( timex3 . getTimexType ( ) ) ; annotation . setTimexValue ( timex3 . getTimexValue ( ) ) ; annotation . setSentId ( timex3 . getSentId ( ) ) ; annotation . setBegin ( timex3 . getBegin ( ) ) ; annotation . setFoundByRule ( timex3 . getFoundByRule ( ) ) ; annotation . setEnd ( timex3 . getEnd ( ) ) ; annotation . setAllTokIds ( timex3 . getAllTokIds ( ) ) ; annotation . setFilename ( timex3 . getFilename ( ) ) ; annotation . setBeginTimex ( timex3 . getTimexId ( ) ) ; annotation . setEndTimex ( timex3 . getTimexId ( ) ) ; newAnnotations . add ( annotation ) ; } } for ( Timex3Interval t3i : newAnnotations ) t3i . addToIndexes ( ) ; }
Build Timex3Interval-Annotations out of Timex3Annotations in jcas.
@author Manuel Dewald
@param jcas