protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } }
protected void addDependencyTreeWithHack(Tree<Pair<String, Integer>> depTree, Constituent parent, int sentenceStart) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.info(parent.getTextAnnotation().toString()); logger.info(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentenceStart, relationLabel); this.addConstituent(childConstituent); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTreeWithHack(child, childConstituent, sentenceStart); } }
protected void addDependencyTree(Tree<Pair<String, Integer>> depTree, int sentStart, Constituent parent) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.error(parent.getTextAnnotation().toString()); logger.error(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentStart, relationLabel); this.addConstituent(childConstituent); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTree(child, sentStart, childConstituent); } }
protected void addDependencyTreeWithHack(Tree<Pair<String, Integer>> depTree, Constituent parent, int sentenceStart) { String word = depTree.getLabel().getFirst(); String token = this.getTextAnnotation().getToken(parent.getStartSpan()); word = treebankTokenHacks(word); token = treebankTokenHacks(token); assert word.trim().length() > 0; assert token.trim().length() > 0; if (!word.equals(token)) { logger.info(parent.getTextAnnotation().toString()); logger.info(depTree.toString()); throw new IllegalStateException("Expecting " + token + ", found " + word + " instead while constructing the dependency tree"); } for (int i = 0; i < depTree.getNumberOfChildren(); i++) { String relationLabel = depTree.getEdgeLabel(i).getFirst(); Tree<Pair<String, Integer>> child = depTree.getChild(i); Constituent childConstituent = getConstituentRelativeToSentenceStart(child, 1.0, sentenceStart, relationLabel); this.addConstituent(childConstituent, true); this.addRelation(new Relation(relationLabel, parent, childConstituent, 1.0)); addDependencyTreeWithHack(child, childConstituent, sentenceStart); } }
this.addRelation(new Relation(edgeLabel, root, childConstituent, 1.0)); this.addParseTree(child, childConstituent, sentenceStartPosition);
this.addRelation(new Relation(edgeLabel, root, childConstituent, 1.0)); this.addParseTree(child, childConstituent, sentenceStartPosition);
/** * Transforms a scored input tree into the constituent-relation graph */ protected void addScoredParseTree(Tree<Pair<String, IntPair>> spanLabeledTree, Tree<Double> scores, Constituent root, int sentenceStartPosition) { for (int childId = 0; childId < spanLabeledTree.getNumberOfChildren(); childId++) { Tree<Pair<String, IntPair>> child = spanLabeledTree.getChild(childId); String edgeLabel; double edgeScore = 0; edgeLabel = PARENT_OF_STRING; double constituentScore = scores.getChild(childId).getLabel(); int start = child.getLabel().getSecond().getFirst() + sentenceStartPosition; int end = child.getLabel().getSecond().getSecond() + sentenceStartPosition; String constituentLabel = child.getLabel().getFirst(); Constituent childConstituent; if (start >= end) { // Ignore constituents with incorrect span bounds logger.debug("Constituent with incorrect span found in " + root.getViewName()); } else { childConstituent = createNewConstituent(start, end, constituentLabel, constituentScore); this.addConstituent(childConstituent, true); this.addRelation(new Relation(edgeLabel, root, childConstituent, edgeScore)); Tree<Double> scoresChild = scores.getChild(childId); this.addScoredParseTree(child, scoresChild, childConstituent, sentenceStartPosition); } } }
/** * Transforms a scored input tree into the constituent-relation graph */ protected void addScoredParseTree(Tree<Pair<String, IntPair>> spanLabeledTree, Tree<Double> scores, Constituent root, int sentenceStartPosition) { for (int childId = 0; childId < spanLabeledTree.getNumberOfChildren(); childId++) { Tree<Pair<String, IntPair>> child = spanLabeledTree.getChild(childId); String edgeLabel; double edgeScore = 0; edgeLabel = PARENT_OF_STRING; double constituentScore = scores.getChild(childId).getLabel(); int start = child.getLabel().getSecond().getFirst() + sentenceStartPosition; int end = child.getLabel().getSecond().getSecond() + sentenceStartPosition; String constituentLabel = child.getLabel().getFirst(); Constituent childConstituent; if (start >= end) { // Ignore constituents with incorrect span bounds logger.debug("Constituent with incorrect span found in " + root.getViewName()); } else { childConstituent = createNewConstituent(start, end, constituentLabel, constituentScore); this.addConstituent(childConstituent); this.addRelation(new Relation(edgeLabel, root, childConstituent, edgeScore)); Tree<Double> scoresChild = scores.getChild(childId); this.addScoredParseTree(child, scoresChild, childConstituent, sentenceStartPosition); } } }