List<CoreMap> sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) {
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); if (sentences != null && sentences.size() > 0) { CoreMap sentence = sentences.get(0);
List<CoreMap> sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) {
Properties props = new Properties(); props.setProperty("annotators","tokenize, ssplit"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation annotation = new Annotation("This is sentence one. This is sentence two."); pipeline.annotate(annotation); List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { System.out.println(sentence); }
Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, stopword"); props.setProperty("customAnnotatorClass.stopword", "intoxicant.analytics.coreNlp.StopwordAnnotator"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation document = new Annotation(example); pipeline.annotate(document); List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
Properties props = new Properties(); props.put("annotators", "tokenize"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation document = new Annotation(text); pipeline.annotate(document); for (CoreLabel token: document.get(TokensAnnotation.class)) { String word = token.get(TextAnnotation.class); }
System.out.println("---"); System.out.println("coref chains"); for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) { System.out.println("\t"+cc); System.out.println(cc.getMentionMap()); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { System.out.println("---"); System.out.println("mentions");
public class CoReferenceAnalyzer { public static void main(String[] args) { Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = "My horse, whom I call Steve, is my best friend. He comforts me when I ride him"; Annotation document = new Annotation(text); pipeline.annotate(document); Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class); System.out.println("Graph: " + graph.toString()); for(Map.Entry<Integer, CorefChain> entry : graph.entrySet()) { CorefChain chain = entry.getValue(); CorefMention repMention = chain.getRepresentativeMention(); System.out.println("Chain: " + chain.toString()); System.out.println("Rep: " + repMention.toString()); } } }
Properties props = new Properties(); props.setProperty("annotators","tokenize, ssplit, pos, lemma, parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String sampleDoc = "This is the first sentence. This is the second one."; Annotation annotation = new Annotation(sampleDoc); pipeline.annotate(annotation); List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); SemanticGraph deps = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); }
String sampleFrenchText = "Le chat mange la souris"; Annotation frenchAnnotation = new Annotation(sampleFrenchText); Properties frenchProperties = StringUtils.argsToProperties(new String[]{"-props", "StanfordCoreNLP-french.properties"}); StanfordCoreNLP pipeline = new StanfordCoreNLP(frenchProperties); pipeline.annotate(frenchAnnotation); for (CoreMap sentence : frenchAnnotation.get(CoreAnnotations.SentencesAnnotation.class)) { Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); System.out.println(sentenceTree);
class Example { public static void main(String[] args) { Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); props.put("dcoref.score", true); pipeline = new StanfordCoreNLP(props); Annotation document = new Annotation("The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons."); pipeline.annotate(document); Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class); println aText for(Map.Entry<Integer, CorefChain> entry : graph) { CorefChain c = entry.getValue(); println "ClusterId: " + entry.getKey(); CorefMention cm = c.getRepresentativeMention(); println "Representative Mention: " + aText.subSequence(cm.startIndex, cm.endIndex); List<CorefMention> cms = c.getCorefMentions(); println "Mentions: "; cms.each { it -> print aText.subSequence(it.startIndex, it.endIndex) + "|"; } println "" } }
Properties props = new Properties(); props.setProperty("annotators","tokenize, ssplit, pos"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation annotation = new Annotation("I'm so happy about my marks"); pipeline.annotate(annotation); List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) { String word = token.get(CoreAnnotations.TextAnnotation.class); // this is the POS tag of the token String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); System.out.println(word + "/" + pos); } }
import edu.stanford.nlp.ling.CoreAnnotations; import edu.stanford.nlp.ling.CoreLabel; import edu.stanford.nlp.pipeline.Annotation; import edu.stanford.nlp.pipeline.StanfordCoreNLP; import edu.stanford.nlp.util.CoreMap; import java.util.Properties; public class NNExample { public static void main(String[] args) { Properties props = new Properties(); props.setProperty("annotators", "tokenize,ssplit,pos"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = "So far, many different types of synchronization have been investigated, such as complete " + "synchronization [8], generalized synchronization [9], phase synchronization [10], " + "lag synchronization [11], projection synchronization [12, 13], and so forth."; Annotation annotation = new Annotation(text); pipeline.annotate(annotation); for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String partOfSpeechTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); if (partOfSpeechTag.equals("NN") || partOfSpeechTag.equals("NNS")) { System.out.println(token.word()); } } } } }
.get(CoreAnnotations.SentencesAnnotation.class); if (sentences != null && sentences.size() > 0) { CoreMap sentence = sentences.get(0);
import edu.stanford.nlp.io.IOUtils; import edu.stanford.nlp.ling.CoreAnnotations; import edu.stanford.nlp.pipeline.*; import edu.stanford.nlp.simple.*; import edu.stanford.nlp.trees.*; import edu.stanford.nlp.util.CoreMap; import edu.stanford.nlp.util.PropertiesUtils; import edu.stanford.nlp.util.StringUtils; import java.util.*; public class SimpleGermanExample { public static void main(String[] args) { String sampleGermanText = "..."; Annotation germanAnnotation = new Annotation(sampleGermanText); Properties germanProperties = StringUtils.argsToProperties( new String[]{"-props", "StanfordCoreNLP-german.properties"}); StanfordCoreNLP pipeline = new StanfordCoreNLP(germanProperties); pipeline.annotate(germanAnnotation); for (CoreMap sentence : germanAnnotation.get(CoreAnnotations.SentencesAnnotation.class)) { Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); System.out.println(sentenceTree); } } }
Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String sentence = "This is an example sentence."; Annotation document = new Annotation(sentence); pipeline.annotate(document); List<CoreMap> sentences = document.get(SentencesAnnotation.class); CoreMap map = sentences.get(0); SemanticGraph semanticGraph = map.get(CollapsedCCProcessedDependenciesAnnotation.class); for (IndexedWord vertex : new ArrayList<>(semanticGraph.vertexSet())) { String tag = vertex.tag(); String ner = vertex.ner(); int beginPosition = vertex.beginPosition(); }
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); pipeline.annotate(review); for (CoreMap sentence : review.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel cl : sentence.get(CoreAnnotations.TokensAnnotation.class)) { if (cl.get(CoreAnnotations.PartOfSpeechAnnotation.class).equals("JJ")) {
List<CoreMap> sentences = document.get(SentencesAnnotation.class); SemanticGraph dependencies1 = sentence.get(CollapsedDependenciesAnnotation.class); dep_type = "CollapsedDependenciesAnnotation";
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); if (sentences != null && sentences.size() > 0) {
Annotation annotation = new Annotation(text); pipeline.annotate(annotation); Tree sentenceTree = annotation.get(CoreAnnotations.SentencesAnnotation.class).get(0).get( TreeCoreAnnotations.TreeAnnotation.class);