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; } }
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 boolean match(TimeExpression te) { if (te != null) { SUTime.Temporal t = te.getTemporal(); if (t != null) { return type.equals(t.getTimexType()); } } return false; } }
public boolean addTemporalExpr(TimeExpression t) { Temporal temp = t.getTemporal(); if (temp != null) { addTemporal(temp); } return temporalExprIndex.add(t); }
public static Temporal parseOrNull(String str) { Annotation doc = new Annotation(str); pipeline.annotate(doc); if (doc.get(CoreAnnotations.SentencesAnnotation.class) == null) { return null; } if (doc.get(CoreAnnotations.SentencesAnnotation.class).isEmpty()) { return null; } List<CoreMap> timexAnnotations = doc.get(TimeAnnotations.TimexAnnotations.class); if (timexAnnotations.size() > 1) { return null; } else if (timexAnnotations.isEmpty()) { return null; } CoreMap timex = timexAnnotations.get(0); if (timex.get(TimeExpression.Annotation.class) == null) { return null; } else { return timex.get(TimeExpression.Annotation.class).getTemporal(); } }
/** * Parse a string with SUTime. * * @throws SUTimeParsingError if anything goes wrong */ public static Temporal parse(String str) throws SUTimeParsingError { try { Annotation doc = new Annotation(str); pipeline.annotate(doc); assert doc.get(CoreAnnotations.SentencesAnnotation.class) != null; assert ! doc.get(CoreAnnotations.SentencesAnnotation.class).isEmpty(); List<CoreMap> timexAnnotations = doc.get(TimeAnnotations.TimexAnnotations.class); if (timexAnnotations.size() > 1) { throw new RuntimeException("Too many timexes for '" + str + '\''); } CoreMap timex = timexAnnotations.get(0); return timex.get(TimeExpression.Annotation.class).getTemporal(); } catch (Exception e) { SUTimeSimpleParser.SUTimeParsingError parsingError = new SUTimeSimpleParser.SUTimeParsingError(str); parsingError.initCause(e); throw parsingError; } }
public int determineRelFlags(CoreMap annotation, TimeExpression te) { int flags = 0; boolean flagsSet = false; if (te.value.getTags() != null) { Value v = te.value.getTags().getTag("resolveTo"); if (v != null && v.get() instanceof Number) { flags = ((Number) v.get()).intValue(); flagsSet = true; } } if (!flagsSet) { if (te.getTemporal() instanceof SUTime.PartialTime) { flags = SUTime.RESOLVE_TO_CLOSEST; } } return flags; } }
if (te.getTemporal() != null && te.getTemporal().getTimexValue() != null) { kept.add(te); } else { if (childTe != null) { resolveTimeExpression(annotation, childTe, refDate); if (childTe.getTemporal() != null && childTe.getTemporal().getTimexValue() != null) { kept.add(childTe);
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); } } } }
for (TimeExpression te:timeExpressions) { CoreMap cm = te.getAnnotation(); SUTime.Temporal temporal = te.getTemporal(); if (temporal != null) { String origText = annotation.get(CoreAnnotations.TextAnnotation.class);
private static SUTime.Time findReferenceDate(List<TimeExpression> timeExpressions) { // Find first full date in this annotation with year, month, and day for (TimeExpression te:timeExpressions) { SUTime.Temporal t = te.getTemporal(); if (t instanceof SUTime.Time) { if (t.isGrounded()) { return t.getTime(); } else if (t instanceof SUTime.PartialTime) { if (JodaTimeUtils.hasYYYYMMDD(t.getTime().getJodaTimePartial())) { return t.getTime(); } else if (JodaTimeUtils.hasYYMMDD(t.getTime().getJodaTimePartial())) { return t.getTime().resolve(SUTime.getCurrentTime()).getTime(); } } } } return null; }
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; } }
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; } }
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; } }
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 boolean addTemporalExpr(TimeExpression t) { Temporal temp = t.getTemporal(); if (temp != null) { addTemporal(temp); } return temporalExprIndex.add(t); }
public boolean match(TimeExpression te) { if (te != null) { SUTime.Temporal t = te.getTemporal(); if (t != null) { return type.equals(t.getTimexType()); } } return false; } }
protected boolean match(TimeExpression te) { if (te != null) { SUTime.Temporal t = te.getTemporal(); if (t != null) { return type.equals(t.getTimexType()); } } return false; } }
public boolean match(TimeExpression te) { if (te != null) { SUTime.Temporal t = te.getTemporal(); if (t != null) { return type.equals(t.getTimexType()); } } return false; } }
public boolean addTemporalExpr(TimeExpression t) { Temporal temp = t.getTemporal(); if (temp != null) { addTemporal(temp); } return temporalExprIndex.add(t); }