use of edu.stanford.nlp.pipeline.CoreEntityMention in project spring-bot by finos.
the class TimeFinder method accept.
@Override
public void accept(Action t) {
try {
if (t instanceof SimpleMessageAction) {
Message m = ((SimpleMessageAction) t).getMessage();
User currentUser = t.getUser();
Addressable a = t.getAddressable();
String messageInString = m.getText();
CoreDocument document = new CoreDocument(messageInString);
stanfordCoreNLP.annotate(document);
for (CoreEntityMention cem : document.entityMentions()) {
System.out.println("temporal expression: " + cem.text());
System.out.println("temporal value: " + cem.coreMap().get(TimeAnnotations.TimexAnnotation.class));
Timex timex = cem.coreMap().get(TimeAnnotations.TimexAnnotation.class);
LocalDateTime ldt = toLocalTime(timex);
if (ldt != null) {
Optional<ReminderList> rl = h.getLastFromHistory(ReminderList.class, a);
int remindBefore;
if (rl.isPresent()) {
remindBefore = rl.get().getRemindBefore();
} else {
remindBefore = reminderProperties.getDefaultRemindBefore();
}
ldt = ldt.minus(remindBefore, ChronoUnit.MINUTES);
Reminder reminder = new Reminder();
reminder.setDescription(messageInString);
reminder.setLocalTime(ldt);
reminder.setAuthor(currentUser);
WorkResponse wr = new WorkResponse(a, reminder, WorkMode.EDIT);
rh.accept(wr);
}
}
}
} catch (Exception e) {
errorHandler.handleError(e);
}
}
Aggregations