private static SUTime.Time FindReferenceDate(IList <TimeExpression> timeExpressions)
 {
     // Find first full date in this annotation with year, month, and day
     foreach (TimeExpression te in timeExpressions)
     {
         SUTime.Temporal t = te.GetTemporal();
         if (t is SUTime.Time)
         {
             if (t.IsGrounded())
             {
                 return(t.GetTime());
             }
             else
             {
                 if (t is 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);
 }
Exemplo n.º 2
0
        public virtual void ParseDateTimeStandardLocalDateTimeFormat()
        {
            LocalDateTime expected = LocalDateTime.Parse("2017-11-02T15:30");

            SUTime.Time actual = SUTime.ParseDateTime("2017-11-02T15:30", true);
            NUnit.Framework.Assert.AreEqual(expected.ToInstant(ZoneId.SystemDefault().GetRules().GetOffset(expected.ToInstant(ZoneOffset.Utc))).ToEpochMilli(), actual.GetJodaTimeInstant().GetMillis());
        }
 public virtual IList <TimeExpression> ExtractTimeExpressions(ICoreMap annotation, string refDateStr, SUTime.TimeIndex timeIndex)
 {
     SUTime.Time refDate = null;
     if (refDateStr != null)
     {
         try
         {
             // TODO: have more robust parsing of document date?  docDate may not have century....
             // TODO: if docDate didn't change, we can cache the parsing of the docDate and not repeat it for every sentence
             refDate = SUTime.ParseDateTime(refDateStr, true);
         }
         catch (Exception e)
         {
             throw new Exception("Could not parse date string: [" + refDateStr + "]", e);
         }
     }
     return(ExtractTimeExpressions(annotation, refDate, timeIndex));
 }
        public virtual IList <ICoreMap> ExtractTimeExpressionCoreMaps(ICoreMap annotation, ICoreMap docAnnotation)
        {
            SUTime.TimeIndex timeIndex;
            // initialized immediately below
            string docDate = null;

            if (docAnnotation != null)
            {
                timeIndex = docAnnotation.Get(typeof(TimeExpression.TimeIndexAnnotation));
                if (timeIndex == null)
                {
                    docAnnotation.Set(typeof(TimeExpression.TimeIndexAnnotation), timeIndex = new SUTime.TimeIndex());
                }
                // default look for the sentence's forum post date
                // if it doesn't have one, back off to the document date
                if (annotation.Get(typeof(CoreAnnotations.SectionDateAnnotation)) != null)
                {
                    docDate = annotation.Get(typeof(CoreAnnotations.SectionDateAnnotation));
                }
                else
                {
                    docDate = docAnnotation.Get(typeof(CoreAnnotations.DocDateAnnotation));
                }
                if (docDate == null)
                {
                    Calendar cal = docAnnotation.Get(typeof(CoreAnnotations.CalendarAnnotation));
                    if (cal == null)
                    {
                        if (options.verbose)
                        {
                            logger.Warn("WARNING: No document date specified");
                        }
                    }
                    else
                    {
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
                        docDate = dateFormat.Format(cal.GetTime());
                    }
                }
            }
            else
            {
                timeIndex = new SUTime.TimeIndex();
            }
            if (StringUtils.IsNullOrEmpty(docDate))
            {
                docDate = null;
            }
            if (timeIndex.docDate == null && docDate != null)
            {
                try
                {
                    // TODO: have more robust parsing of document date?  docDate may not have century....
                    // TODO: if docDate didn't change, we can cache the parsing of the docDate and not repeat it for every sentence
                    timeIndex.docDate = SUTime.ParseDateTime(docDate, true);
                }
                catch (Exception e)
                {
                    throw new Exception("Could not parse date string: [" + docDate + "]", e);
                }
            }
            string sectionDate = annotation.Get(typeof(CoreAnnotations.SectionDateAnnotation));
            string refDate     = (sectionDate != null) ? sectionDate : docDate;

            return(ExtractTimeExpressionCoreMaps(annotation, refDate, timeIndex));
        }
Exemplo n.º 5
0
 public virtual void ParseDateTimeStandardInstantFormat()
 {
     NUnit.Framework.Assert.AreEqual(Instant.Parse("2017-11-02T19:30:00Z").ToEpochMilli(), SUTime.ParseDateTime("2017-11-02T19:30:00Z", true).GetJodaTimeInstant().GetMillis());
 }