当我使用SUTime的API时,我提供文本并接收CoreMap
个对象的列表,每个对象都详细说明了文本中时间表达式的属性。我希望采用这样的CoreMap
并将其转换为Date
或Calendar
对象,以便于处理和操作。
SUTime API中是否有这样的方法?其他地方的事情呢?
是否有一种反向方法可以在CoreMap
或Date
对象中构建Calendar
?
答案 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对象(因此可能存在一些例外情况)。