如何将SUTime对象转换为常规Calendar或Date对象?

时间:2016-04-13 18:49:10

标签: java stanford-nlp sutime

当我使用SUTime的API时,我提供文本并接收CoreMap个对象的列表,每个对象都详细说明了文本中时间表达式的属性。我希望采用这样的CoreMap并将其转换为DateCalendar对象,以便于处理和操作。

SUTime API中是否有这样的方法?其他地方的事情呢?

是否有一种反向方法可以在CoreMapDate对象中构建Calendar

1 个答案:

答案 0 :(得分:1)

要从SUTime提取的CoreMap cm中获取Calendar对象,您可以尝试:

Calendar calendar = cm.get(TimeAnnotations.TimexAnnotation.class).getDate(); (见https://github.com/stanfordnlp/CoreNLP/blob/master/src/edu/stanford/nlp/time/Timex.java

请注意,并非SUTime识别的所有时间表达式都将解析为某个时间点或Calendar对象(因此可能存在一些例外情况)。