// 7:00 in the evening => 7:00 pm
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; dayPortionIndex == -1 && i < tokenSize; i++) {
Token t = tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}
int timeIndex = -1;
for (int i = 0; timeIndex == -1 && i < tokenSize; i++) {
Token t = tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}
if (dayPortionIndex != -1 && timeIndex != -1) {
Token t1 = tokens.get(dayPortionIndex);
Tag<RepeaterDayPortion<?>> t1Tag = t1.getTag(RepeaterDayPortion.class);
Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if (RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType) || RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType) || RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}
}
// int tokenSize = tokens.size();
// for (int i = 0; i < tokenSize; i++) {
// Token t0 = tokens.get(i);
// if (i < tokenSize - 1) {
// Token t1 = tokens.get(i + 1);
// RepeaterDayPortion<?> t1Tag = t1.getTag(RepeaterDayPortion.class);
// if (t1Tag != null && t0.getTag(RepeaterTime.class) != null) {
// if (t1Tag.getType() == RepeaterDayPortion.DayPortion.MORNING) {
// t1.untag(RepeaterDayPortion.class);
// t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
// }
// else if (t1Tag.getType() == RepeaterDayPortion.DayPortion.AFTERNOON || t1Tag.getType() == RepeaterDayPortion.DayPortion.EVENING || t1Tag.getType() == RepeaterDayPortion.DayPortion.NIGHT) {
// t1.untag(RepeaterDayPortion.class);
// t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
// }
// }
// }
// }
// handle ambiguous times if :ambiguous_time_range is specified
if (options.getAmbiguousTimeRange() != 0) {
List<Token> ttokens = new LinkedList<Token>();
for (int i = 0; i < tokenSize; i++) {
Token t0 = tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = tokens.get(i + 1);
}
if (t0.getTag(RepeaterTime.class) != null && t0.getTag(RepeaterTime.class).getType().isAmbiguous() && (t1 == null || t1.getTag(RepeaterDayPortion.class) == null)) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}