if (te.getTemporal() != null && te.getTemporal().getTimexValue() != null) { kept.add(te); } else { List<? extends CoreMap> children = te.getAnnotation().get(TimeExpression.ChildrenAnnotation.class); if (children != null) { for (CoreMap child:children) { if (childTe != null) { resolveTimeExpression(annotation, childTe, refDate); if (childTe.getTemporal() != null && childTe.getTemporal().getTimexValue() != null) { kept.add(childTe); List<TimeExpression> nestedTimeExpressions = new ArrayList<>(); for (TimeExpression te : timeExpressions) { if (te.isIncludeNested()) { List<? extends CoreMap> children = te.getAnnotation().get(TimeExpression.ChildrenAnnotation.class); if (children != null) { for (CoreMap child:children) {
@Override public boolean extractAnnotation(Env env, List<? extends CoreMap> source) { boolean okay = super.extractAnnotation(env, source); //super.extractAnnotation(source, CoreMapAttributeAggregator.getDefaultAggregators(), //TimeExpression.Annotation.class, TimeExpression.ChildrenAnnotation.class); if (okay) { return addMod(); } else { return false; } }
public TimeExpression(Interval<Integer> charOffsets, Interval<Integer> tokenOffsets, Function<CoreMap, SUTime.Temporal> temporalFunc, double priority, double weight) { super(charOffsets, tokenOffsets, getSingleAnnotationExtractor(temporalFunc), priority, weight); }
public boolean addMod() { SUTime.Temporal t = getTemporal(); if (t != null) { if (t != SUTime.TIME_NONE_OK) { setTemporal(t); return true; } else { return false; } } else { return true; } }
List<CoreMap> coreMaps = new ArrayList<>(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);
public Temporal getTemporal(String s) { Matcher m = ID_PATTERN.matcher(s); if (m.matches()) { String prefix = m.group(1); int id = Integer.parseInt(m.group(2)); if ("t".equals(prefix)) { TimeExpression te = temporalExprIndex.get(id); return (te != null)? te.getTemporal(): null; } else if (prefix.isEmpty()) { return temporalIndex.get(id); } } return null; }
public TimeExpression apply(MatchedExpression in) { if (in == null) return null; if (in instanceof TimeExpression) return (TimeExpression) in; TimeExpression newExpr = new TimeExpression(in); if (newExpr.getAnnotation().get(TimeExpression.Annotation.class) == in) { newExpr.getAnnotation().set(TimeExpression.Annotation.class, newExpr); } return newExpr; } };
private void annotateTimeExpressions(List<? extends CoreMap> chunks, List<TimeExpression> timeExpressions) { List<TimeExpression> toDiscard = new ArrayList<TimeExpression>(); for (TimeExpression te:timeExpressions) { // Add attributes and tids try { @SuppressWarnings("unused") CoreMap chunk = te.extractAnnotation(chunks); SUTime.Temporal temporal = te.getTemporal(); if (temporal != null) { if (temporal != SUTime.TIME_NONE_OK) { te.temporal = timexPatterns.addMod(te.text, temporal); // Timex timex = Timex.fromMap(chunk.get(CoreAnnotations.TextAnnotation.class), temporal.getTimexAttributes(timeIndex)); // chunk.set(Timex.Annotation.class, timex); } else { toDiscard.add(te); } } else { logger.log(Level.WARNING, "Unable to get temporal for time expression " + te); } } catch (Exception ex) { logger.log(Level.WARNING, "Error extracting annotation with temporal from time expression: " + te, ex); } } timeExpressions.removeAll(toDiscard); }
private List<? extends CoreMap> replaceMerged(List<? extends CoreMap> list, List<TimeExpression> timeExprs) { Collections.sort(timeExprs, TIME_EXPR_TOKEN_OFFSET_COMPARATOR); List<CoreMap> merged = new ArrayList<CoreMap>(list.size()); // Approximate size int last = 0; for (TimeExpression timeExpr:timeExprs) { int start = timeExpr.chunkOffsets.first(); int end = timeExpr.chunkOffsets.second(); if (start >= last) { merged.addAll(list.subList(last,start)); CoreMap m = timeExpr.getAnnotation(); merged.add(m); last = end; } } // Add rest of elements if (last < list.size()) { merged.addAll(list.subList(last, list.size())); } return merged; }
public boolean extract(String str, List<TimeExpression> out) { //List<CoreLabel> str = annotation.get(CoreAnnotations.TextAnnotation.class); boolean extracted = false; Matcher m = pattern.matcher(str); while (m.find()) { TimeExpression te = new TimeExpression(Interval.toInterval(m.start(group), m.end(group), Interval.INTERVAL_OPEN_END), null, extractor, 0); te.includeNested = includeNested; out.add(te); extracted = true; } return extracted; }
public boolean match(TimeExpression te) { if (te != null) { SUTime.Temporal t = te.getTemporal(); if (t != null) { return type.equals(t.getTimexType()); } } return false; } }
private void resolveTimeExpression(CoreMap annotation, TimeExpression te, SUTime.Time docDate) { 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.debug("Error resolving " + temporal + ", using docDate=" + docDate); } if (grounded != temporal) { te.origTemporal = temporal; te.setTemporal(grounded); } } catch (Exception ex) { if (options.verbose) { logger.warn("Error resolving " + temporal, ex); logger.warn(ex); } } } }
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);
private void annotateTimeExpressions(CoreMap annotation, List<TimeExpression> timeExpressions) { List<TimeExpression> toDiscard = new ArrayList<TimeExpression>(); for (TimeExpression te:timeExpressions) { // Add attributes and tids try { @SuppressWarnings("unused") CoreMap chunk = te.extractAnnotation(annotation); SUTime.Temporal temporal = te.getTemporal(); if (temporal != null) { if (temporal != SUTime.TIME_NONE_OK) { te.temporal = timexPatterns.addMod(te.text, temporal); // Timex timex = Timex.fromMap(chunk.get(CoreAnnotations.TextAnnotation.class), temporal.getTimexAttributes(timeIndex)); // chunk.set(Timex.Annotation.class, timex); } else { toDiscard.add(te); } } else { logger.log(Level.WARNING, "Unable to get temporal for time expression " + te); logger.log(Level.WARNING, "Temporal func: " + te.temporalFunc); } } catch (Exception ex) { logger.log(Level.WARNING, "Error extracting annotation with temporal from time expression: " + te, ex); } } timeExpressions.removeAll(toDiscard); }
public boolean extract(List<? extends CoreMap> tokens, List<TimeExpression> out) { boolean extracted = false; SequenceMatcher<CoreMap> m = pattern.getMatcher(tokens); while (m.find()) { TimeExpression te = new TimeExpression(null, Interval.toInterval(m.start(group), m.end(group), Interval.INTERVAL_OPEN_END), extractor, m.score()); te.includeNested = includeNested; out.add(te); extracted = true; } return extracted; }
public boolean addTemporalExpr(TimeExpression t) { Temporal temp = t.getTemporal(); if (temp != null) { addTemporal(temp); } return temporalExprIndex.add(t); }
if (te.getTemporal() != null && te.getTemporal().getTimexValue() != null) { kept.add(te); } else { List<? extends CoreMap> children = te.getAnnotation().get(TimeExpression.ChildrenAnnotation.class); if (children != null) { for (CoreMap child:children) { if (childTe != null) { resolveTimeExpression(annotation, childTe, refDate); if (childTe.getTemporal() != null && childTe.getTemporal().getTimexValue() != null) { kept.add(childTe); 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) {
public boolean addMod() { SUTime.Temporal t = getTemporal(); if (t != null) { if (t != SUTime.TIME_NONE_OK) { setTemporal(t); return true; } else { return false; } } else { return true; } }
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);
@Override public boolean extractAnnotation(Env env, CoreMap sourceAnnotation) { boolean okay = super.extractAnnotation(env, sourceAnnotation); //super.extractAnnotation(sourceAnnotation, CoreAnnotations.NumerizedTokensAnnotation.class, //CoreMapAttributeAggregator.DEFAULT_NUMERIC_TOKENS_AGGREGATORS, //TimeExpression.Annotation.class, TimeExpression.ChildrenAnnotation.class); if (okay) { return addMod(); } else { return false; } }