/*Stem the given word with, return the stemmed word */ public List <string> Stem(string word) { if (pipeline == null) { Initial(); } var lemmas = new List <String>(); // create an empty Annotation just with the given text var document = new Annotation(word); // run all Annotators on this text try { pipeline.annotate(document); } catch (Exception) { return(null); } // Iterate over all of the sentences found var senObj = new edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation(); var obj = document.get(senObj.getClass()); var tokenObj = new edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation(); var lemmaObj = new edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation(); var sentences = (ArrayList)obj; foreach (CoreMap sentence in sentences) { // Iterate over all tokens in a sentence lemmas.AddRange(from CoreLabel token in (ArrayList)sentence.get(tokenObj.getClass()) select(string) token.get(lemmaObj.getClass())); } return(lemmas); }
public List <string> SplitSequence(string sequence) { if (pipeline == null) { Initial(); } if (sequence == null) { throw new Exception("Sequence should not be null for sentence splitting!"); } var document = new Annotation(sequence); pipeline.annotate(document); var senObj = new edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation(); var sentences = (ArrayList)document.get(senObj.getClass()); tokensBySentence = new List <string[]>(); for (var i = 0; i < sentences.size(); i++) { var sen = sentences.get(i); } return((from CoreMap sentence in sentences select sentence.ToString()).ToList()); }
private StafordCoreNlpSentimentClass FindSentiment(string text) { var sentimentList = new List <int>(); if (!String.IsNullOrWhiteSpace(text)) { var annotation = _nlp.process(text); var SentencesAnnotationClass = new edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation().getClass(); var SentimentAnnotatedTreeClass = new edu.stanford.nlp.sentiment.SentimentCoreAnnotations.AnnotatedTree().getClass(); java.util.ArrayList bla = (java.util.ArrayList)annotation.get(SentencesAnnotationClass); foreach (edu.stanford.nlp.util.CoreMap sentence in bla) { var tree = (edu.stanford.nlp.trees.Tree)sentence.get(SentimentAnnotatedTreeClass); int sentiment = edu.stanford.nlp.neural.rnn.RNNCoreAnnotations.getPredictedClass(tree); sentimentList.Add(sentiment); } } return(SummarizeSentiment(sentimentList)); }