private IList <ICoreMap> ToCoreMaps(ICoreMap annotation, IList <TimeExpression> timeExpressions, SUTime.TimeIndex timeIndex)
        {
            if (timeExpressions == null)
            {
                return(null);
            }
            IList <ICoreMap> coreMaps = new List <ICoreMap>(timeExpressions.Count);

            foreach (TimeExpression te in timeExpressions)
            {
                ICoreMap        cm       = te.GetAnnotation();
                SUTime.Temporal temporal = te.GetTemporal();
                if (temporal != null)
                {
                    string origText = annotation.Get(typeof(CoreAnnotations.TextAnnotation));
                    string text     = cm.Get(typeof(CoreAnnotations.TextAnnotation));
                    if (origText != null)
                    {
                        // Make sure the text is from original (and not from concatenated tokens)
                        ChunkAnnotationUtils.AnnotateChunkText(cm, annotation);
                        text = cm.Get(typeof(CoreAnnotations.TextAnnotation));
                    }
                    IDictionary <string, string> timexAttributes;
                    try
                    {
                        timexAttributes = temporal.GetTimexAttributes(timeIndex);
                        if (options.includeRange)
                        {
                            SUTime.Temporal rangeTemporal = temporal.GetRange();
                            if (rangeTemporal != null)
                            {
                                timexAttributes["range"] = rangeTemporal.ToString();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (options.verbose)
                        {
                            logger.Warn("Failed to get attributes from " + text + ", timeIndex " + timeIndex);
                            logger.Warn(e);
                        }
                        continue;
                    }
                    Timex timex;
                    try
                    {
                        timex = Timex.FromMap(text, timexAttributes);
                    }
                    catch (Exception e)
                    {
                        if (options.verbose)
                        {
                            logger.Warn("Failed to process timex " + text + " with attributes " + timexAttributes);
                            logger.Warn(e);
                        }
                        continue;
                    }
                    System.Diagnostics.Debug.Assert(timex != null);
                    // Timex.fromMap never returns null and if it exceptions, we've already done a continue
                    cm.Set(typeof(TimeAnnotations.TimexAnnotation), timex);
                    coreMaps.Add(cm);
                }
            }
            return(coreMaps);
        }
コード例 #2
0
 private static void ResolveAndCheckRange(string message, SUTime.Temporal t, SUTime.Time anchor, string expected)
 {
     SUTime.Temporal res   = t.Resolve(anchor);
     SUTime.Range    range = res.GetRange();
     NUnit.Framework.Assert.AreEqual(expected, range.ToISOString(), message);
 }