/*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 void Parse(string sentence) { if (pipeline == null) { Initial(); } Annotation context = new Annotation(sentence); pipeline.annotate(context); this.tokens = (ArrayList)context.get(tokenObj.getClass()); var sentences = (ArrayList)context.get(senObj.getClass()); foreach (CoreMap sen in sentences) { this.dependencies = (SemanticGraph)sen.get(depObj.getClass()); break; } }
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()); }