Search in sources :

Example 1 with CoreDocument

use of edu.stanford.nlp.pipeline.CoreDocument in project CoreNLP by stanfordnlp.

the class FrenchTokenizerAnnotatorITest method testFrench.

@Test
public void testFrench() {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, mwt");
    props.setProperty("ssplit.eolonly", "true");
    props.setProperty("tokenize.language", "fr");
    props.setProperty("mwt.mappingFile", "edu/stanford/nlp/models/mwt/french/french-mwt.tsv");
    props.setProperty("mwt.pos.model", "edu/stanford/nlp/models/mwt/french/french-mwt.tagger");
    props.setProperty("mwt.statisticalMappingFile", "edu/stanford/nlp/models/mwt/french/french-mwt-statistical.tsv");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    int sentNum = 0;
    for (String exampleSentence : frenchSentences) {
        List<String> exampleSentenceTokens = frenchSentenceTokenLists.get(sentNum);
        CoreDocument exampleSentenceCoreDocument = new CoreDocument(exampleSentence);
        pipeline.annotate(exampleSentenceCoreDocument);
        for (int i = 0; i < exampleSentenceTokens.size(); i++) {
            assertEquals(exampleSentenceTokens.get(i), exampleSentenceCoreDocument.tokens().get(i).word());
        }
        sentNum++;
    }
}
Also used : CoreDocument(edu.stanford.nlp.pipeline.CoreDocument) Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Test(org.junit.Test)

Example 2 with CoreDocument

use of edu.stanford.nlp.pipeline.CoreDocument in project CoreNLP by stanfordnlp.

the class SentenceUtilsITest method testRebuildingText.

@Test
public void testRebuildingText() {
    // set up basic English pipeline
    Properties basicProperties = new Properties();
    basicProperties.setProperty("annotators", "tokenize,ssplit");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(basicProperties);
    String text = "Let's hope this doesn't not work properly.  Especially across sentences. ";
    CoreDocument doc = new CoreDocument(pipeline.process(text));
    String rebuiltText = SentenceUtils.listToOriginalTextString(doc.tokens());
    assertTrue(text.equals(rebuiltText));
}
Also used : CoreDocument(edu.stanford.nlp.pipeline.CoreDocument) Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Test(org.junit.Test)

Example 3 with CoreDocument

use of edu.stanford.nlp.pipeline.CoreDocument in project CoreNLP by stanfordnlp.

the class SentenceUtilsITest method testRebuildingMWTText.

@Test
public void testRebuildingMWTText() throws IOException {
    // set up French properties
    Properties frenchProperties = LanguageInfo.getLanguageProperties("french");
    frenchProperties.setProperty("annotators", "tokenize,ssplit,mwt");
    StanfordCoreNLP frenchPipeline = new StanfordCoreNLP(frenchProperties);
    String frenchText = "Le but des bandes de roulement est d'augmenter la traction.";
    CoreDocument frenchDoc = new CoreDocument(frenchPipeline.process(frenchText));
    String rebuiltFrenchText = SentenceUtils.listToOriginalTextString(frenchDoc.tokens());
    assertTrue(frenchText.equals(rebuiltFrenchText));
}
Also used : CoreDocument(edu.stanford.nlp.pipeline.CoreDocument) Properties(java.util.Properties) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) Test(org.junit.Test)

Example 4 with CoreDocument

use of edu.stanford.nlp.pipeline.CoreDocument 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)4 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 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