public TimeExpression apply(MatchResult matched) {
   TimeExpression te =
       new TimeExpression(
           Interval.toInterval(
               matched.start(group), matched.end(group), Interval.INTERVAL_OPEN_END),
           null,
           extractor,
           0);
   te.setIncludeNested(includeNested);
   return te;
 }
 private List<CoreMap> toCoreMaps(
     CoreMap annotation, List<TimeExpression> timeExpressions, SUTime.TimeIndex timeIndex) {
   if (timeExpressions == null) return null;
   List<CoreMap> coreMaps = new ArrayList<CoreMap>(timeExpressions.size());
   for (TimeExpression te : timeExpressions) {
     CoreMap cm = te.getAnnotation();
     SUTime.Temporal temporal = te.getTemporal();
     if (temporal != null) {
       String origText = annotation.get(CoreAnnotations.TextAnnotation.class);
       String text = cm.get(CoreAnnotations.TextAnnotation.class);
       if (origText != null) {
         // Make sure the text is from original (and not from concatenated tokens)
         ChunkAnnotationUtils.annotateChunkText(cm, annotation);
         text = cm.get(CoreAnnotations.TextAnnotation.class);
       }
       Map<String, String> timexAttributes;
       try {
         timexAttributes = temporal.getTimexAttributes(timeIndex);
         if (options.includeRange) {
           SUTime.Temporal rangeTemporal = temporal.getRange();
           if (rangeTemporal != null) {
             timexAttributes.put("range", rangeTemporal.toString());
           }
         }
       } catch (Exception e) {
         logger.log(
             Level.WARNING,
             "Failed to get attributes from " + text + ", timeIndex " + timeIndex,
             e);
         continue;
       }
       Timex timex;
       try {
         timex = Timex.fromMap(text, timexAttributes);
       } catch (Exception e) {
         logger.log(
             Level.WARNING,
             "Failed to process " + text + " with attributes " + timexAttributes,
             e);
         continue;
       }
       cm.set(TimexAnnotation.class, timex);
       if (timex != null) {
         coreMaps.add(cm);
       } else {
         logger.warning("No timex expression for: " + text);
       }
     }
   }
   return coreMaps;
 }
  public List<TimeExpression> extractTimeExpressions(CoreMap annotation, String docDateStr) {
    List<CoreMap> mergedNumbers = NumberNormalizer.findAndMergeNumbers(annotation);
    annotation.set(CoreAnnotations.NumerizedTokensAnnotation.class, mergedNumbers);

    // TODO: docDate may not have century....
    SUTime.Time docDate = timexPatterns.parseDateTime(docDateStr);

    List<? extends MatchedExpression> matchedExpressions =
        expressionExtractor.extractExpressions(annotation);
    List<TimeExpression> timeExpressions = new ArrayList<TimeExpression>(matchedExpressions.size());
    for (MatchedExpression expr : matchedExpressions) {
      if (expr instanceof TimeExpression) {
        timeExpressions.add((TimeExpression) expr);
      } else {
        timeExpressions.add(new TimeExpression(expr));
      }
    }

    // Add back nested time expressions for ranges....
    // For now only one level of nesting...
    if (options.includeNested) {
      List<TimeExpression> nestedTimeExpressions = new ArrayList<TimeExpression>();
      for (TimeExpression te : timeExpressions) {
        if (te.isIncludeNested()) {
          List<? extends CoreMap> children =
              te.getAnnotation().get(TimeExpression.ChildrenAnnotation.class);
          if (children != null) {
            for (CoreMap child : children) {
              TimeExpression childTe = child.get(TimeExpression.Annotation.class);
              if (childTe != null) {
                nestedTimeExpressions.add(childTe);
              }
            }
          }
        }
      }
      timeExpressions.addAll(nestedTimeExpressions);
    }
    Collections.sort(timeExpressions, MatchedExpression.EXPR_TOKEN_OFFSETS_NESTED_FIRST_COMPARATOR);
    timeExpressions = filterInvalidTimeExpressions(timeExpressions);

    // Some resolving is done even if docDate null...
    if (
    /*docDate != null && */ timeExpressions != null) {
      resolveTimeExpressions(annotation, timeExpressions, docDate);
    }
    // Annotate timex
    return timeExpressions;
  }
 public SUTime.Temporal apply(MatchResult in) {
   if (in instanceof SequenceMatchResult) {
     SequenceMatchResult<CoreMap> mr = (SequenceMatchResult<CoreMap>) (in);
     if (group >= 0) {
       List<? extends CoreMap> matched = mr.groupNodes(group);
       if (matched != null) {
         int i = (nodeIndex >= 0) ? 0 : (matched.size() + nodeIndex);
         TimeExpression te = getTimeExpression(matched, i);
         if (te != null) {
           return te.getTemporal();
         }
       }
     }
   }
   return null;
 }
 private void resolveTimeExpressions(
     CoreMap annotation, List<TimeExpression> timeExpressions, SUTime.Time docDate) {
   for (TimeExpression te : timeExpressions) {
     SUTime.Temporal temporal = te.getTemporal();
     if (temporal != null) {
       // TODO: use correct time for anchor
       try {
         int flags = timexPatterns.determineRelFlags(annotation, te);
         // int flags = 0;
         SUTime.Temporal grounded = temporal.resolve(docDate, flags);
         if (grounded == null) {
           logger.warning("Error resolving " + temporal + ", using docDate=" + docDate);
         }
         if (grounded != temporal) {
           te.origTemporal = temporal;
           te.setTemporal(grounded);
         }
       } catch (Exception ex) {
         logger.log(Level.WARNING, "Error resolving " + temporal, ex);
       }
     }
   }
 }