List of usage examples for edu.stanford.nlp.trees Tree taggedLabeledYield
public List<CoreLabel> taggedLabeledYield()
From source file:com.daemon.sentiment.FeatureMatrix.java
License:Open Source License
/** * POS tagging features//from ww w. ja v a2s. c o m * * Words are tagged with their respective part-of-speech tag as determined * by the Stanford parser * * @param tokens * Tokenized text of the tweet * @param tokensPOSTagged * Tokenized text of the tweet, possibly with negations from the * previous step * @return Reference to the second parameter, which now has POS annotations, * e.g. "love $NN$" */ private List<String> addPOSTags(List<String> tokens, List<String> tokensPOSTagged) { Tree stanfordTree; // Parser needs the tokens-list in a HasWord format List<HasWord> sentence = new ArrayList<HasWord>(); for (String token : tokens) { sentence.add(new Word(token)); } // Parse the sentence stanfordTree = lexicalizedParser.apply(sentence); // add results (POS tags) in tokensPOSTagged-list int i = 0; for (CoreLabel label : stanfordTree.taggedLabeledYield()) { tokensPOSTagged.set(i, tokensPOSTagged.get(i) + " $" + label.toString("value") + "$"); i++; } return tokensPOSTagged; }