Created
June 26, 2017 02:07
-
-
Save danbills/c5d860fce712adbeb61af5a875819ebe to your computer and use it in GitHub Desktop.
Ammonite script to run CoreNLP embedded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ivy.`edu.stanford.nlp:stanford-corenlp:3.8.0` | |
import edu.stanford.nlp.pipeline._ | |
import edu.stanford.nlp.ling.CoreAnnotations._ | |
import edu.stanford.nlp.trees.TreeCoreAnnotations._ | |
import java.util._ | |
import scala.collection.JavaConverters._ | |
// creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution | |
val props = new Properties(); | |
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); | |
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz"); | |
props.setProperty("ner.useSUTime", "0"); | |
props.setProperty("ssplit.isOneSentence", "true"); | |
props.setProperty("tokenize.language", "en"); | |
val pipeline = new StanfordCoreNLP(props); | |
// read some text in the text variable | |
val text = "Hello there, I'd like to know what's in this sentence."; | |
// create an empty Annotation just with the given text | |
val document = new Annotation(text); | |
// run all Annotators on this text | |
val x = pipeline.annotate(document); | |
val sentences = document.get(classOf[SentencesAnnotation]); | |
println(x) | |
println(s"sentences is $sentences") | |
sentences.asScala.foreach{ | |
s => | |
val tree = s.get(classOf[TreeAnnotation]); | |
println(tree) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment