@SuppressWarnings("unused") private Tree doOneSentence(List<? extends CoreLabel> words) { // convert to CyclicCoreLabels because the parser hates CoreLabels List<CyclicCoreLabel> newWords = new ArrayList<CyclicCoreLabel>(); for (CoreLabel fl : words) { CyclicCoreLabel ml = new CyclicCoreLabel(); ml.setWord(fl.word()); ml.setValue(fl.word()); newWords.add(ml); } if(maxSentenceLength <= 0 || newWords.size() < maxSentenceLength) { return parser.apply(newWords); } else { return ParserAnnotatorUtils.xTree(newWords); } } }
public void annotate(Annotation annotation) { if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // parse a tree for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { Tree tree = null; List<CoreLabel> words = sentence.get(CoreAnnotations.TokensAnnotation.class); if (VERBOSE) { System.err.println("Parsing: " + words); } // generate the constituent tree if(maxSentenceLength <= 0 || words.size() < maxSentenceLength) tree = parser.apply(words); else tree = ParserAnnotatorUtils.xTree(words); if (treeMap != null) { tree = treeMap.apply(tree); } ParserAnnotatorUtils.fillInParseAnnotations(VERBOSE, sentence, tree); } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
public void annotate(Annotation annotation) { if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // parse a tree for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { Tree tree = null; List<CoreLabel> words = sentence.get(CoreAnnotations.TokensAnnotation.class); if (VERBOSE) { System.err.println("Parsing: " + words); } int maxSentenceLength = parser.getMaxSentenceLength(); // generate the constituent tree if (maxSentenceLength <= 0 || words.size() < maxSentenceLength) { tree = parser.getBestParse(words); } else { tree = ParserAnnotatorUtils.xTree(words); } ParserAnnotatorUtils.fillInParseAnnotations(VERBOSE, sentence, tree); } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } } }