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++;
}
}
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));
}
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));
}
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);
}
}
Aggregations