Search in sources :

Example 1 with CoreEntityMention

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);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(org.finos.symphony.toolkit.workflow.content.User) Message(org.finos.symphony.toolkit.workflow.content.Message) CoreDocument(edu.stanford.nlp.pipeline.CoreDocument) ParseException(java.text.ParseException) CoreEntityMention(edu.stanford.nlp.pipeline.CoreEntityMention) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) TimeAnnotations(edu.stanford.nlp.time.TimeAnnotations) Timex(edu.stanford.nlp.time.Timex) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Aggregations

CoreDocument (edu.stanford.nlp.pipeline.CoreDocument)1 CoreEntityMention (edu.stanford.nlp.pipeline.CoreEntityMention)1 TimeAnnotations (edu.stanford.nlp.time.TimeAnnotations)1 Timex (edu.stanford.nlp.time.Timex)1 ParseException (java.text.ParseException)1 LocalDateTime (java.time.LocalDateTime)1 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)1 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)1 Message (org.finos.symphony.toolkit.workflow.content.Message)1 User (org.finos.symphony.toolkit.workflow.content.User)1 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)1