/** * Makes a new constituent spanning {@code start} to {@code end} with the label * {@code constituentLabel} and score {@code constituentScore}. */ private Constituent createNewConstituent(int start, int end, String constituentLabel, double constituentScore) { return new Constituent(constituentLabel, constituentScore, this.getViewName(), this.getTextAnnotation(), start, end); }
/** * Makes a new constituent spanning {@code start} to {@code end} with the label * {@code constituentLabel} and score {@code constituentScore}. */ private Constituent createNewConstituent(int start, int end, String constituentLabel, double constituentScore) { return new Constituent(constituentLabel, constituentScore, this.getViewName(), this.getTextAnnotation(), start, end); }
/** * Set the parse tree of the {@code sentenceId}th sentence. */ public void setScoredParseTree(int sentenceId, Tree<String> tree, Tree<Double> scores) { safeInitializeTrees(); if (!this.getViewName().startsWith("PARSE")) { throw new IllegalStateException("Cannot set a Tree<String> object " + "as the dependency tree." + " Need a Tree<String, Integer> " + "to recover dependency token information. "); } this.trees.set(sentenceId, tree); Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree); int sentenceStart = getSentenceStart(sentenceId); Pair<String, IntPair> rootLabel = spanLabeledTree.getLabel(); IntPair rootSpan = rootLabel.getSecond(); int rootStart = rootSpan.getFirst() + sentenceStart; int rootEnd = rootSpan.getSecond() + sentenceStart; Constituent root = createNewConstituent(rootStart, rootEnd, rootLabel.getFirst(), scores.getLabel()); this.addConstituent(root); addScoredParseTree(spanLabeledTree, scores, root, this.getTextAnnotation().getSentence(sentenceId).getStartSpan()); }
/** * Set the parse tree of the {@code sentenceId}th sentence. */ public void setScoredParseTree(int sentenceId, Tree<String> tree, Tree<Double> scores) { safeInitializeTrees(); if (!this.getViewName().startsWith("PARSE")) { throw new IllegalStateException("Cannot set a Tree<String> object " + "as the dependency tree." + " Need a Tree<String, Integer> " + "to recover dependency token information. "); } this.trees.set(sentenceId, tree); Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree); int sentenceStart = getSentenceStart(sentenceId); Pair<String, IntPair> rootLabel = spanLabeledTree.getLabel(); IntPair rootSpan = rootLabel.getSecond(); int rootStart = rootSpan.getFirst() + sentenceStart; int rootEnd = rootSpan.getSecond() + sentenceStart; Constituent root = createNewConstituent(rootStart, rootEnd, rootLabel.getFirst(), scores.getLabel()); this.addConstituent(root); addScoredParseTree(spanLabeledTree, scores, root, this.getTextAnnotation().getSentence(sentenceId).getStartSpan()); }