// if survive, return true // best-deduction is always kept private boolean pruningEdge(HyperEdge dt, HGNode parent) { /** * TODO: theoretically, if an item is get called, then its best deduction should always be kept * even just by the threshold-checling. In reality, due to precision of Double, the * threshold-checking may not be perfect */ if (dt != parent.bestHyperedge) { // best deduction should always survive if the Item is get // called // ### prune? if (shouldPruneHyperedge(dt, parent)) { return false; // early stop } } // ### still survive, recursive call all my ant-items if (null != dt.getTailNodes()) { for (HGNode ant_it : dt.getTailNodes()) { pruningNode(ant_it); // recursive call on each ant item, note: the ant_it will not be pruned // as I need it } } // ### if get to here, then survive; remember: if I survive, then my upper-item must survive numSurvivedEdges++; return true; // survive }
private boolean shouldPruneHyperedge(HyperEdge dt, HGNode parent) { // ### get merit double postLogProb = getEdgeUnormalizedPosteriorLogProb(dt, parent); if (dt.getRule() != null && dt.getRule().getOwner() == glueGrammarOwner && dt.getRule().getArity() == 2) { // specicial rule: S->S X // TODO return (postLogProb - this.bestLogProb < THRESHOLD_GLUE); } else { return (postLogProb - this.bestLogProb < THRESHOLD_GENERAL); } }
private static int[] getNewSource(boolean isGlue, HyperEdge edge) { BilingualRule rule = (BilingualRule) edge.getRule(); int[] english = rule.getEnglish(); // if this is a unary abstract rule, just return null // TODO: except glue rules! if (english.length == 1 && english[0] < 0 && !isGlue) return null; int currNT = 1; int[] result = new int[english.length]; for (int i = 0; i < english.length; i++) { int curr = english[i]; if (!Vocabulary.nt(curr)) { result[i] = curr; } else { int index = -curr - 1; int label = getLabelWithSpan(edge.getAntNodes().get(index)); result[i] = label * 2 - currNT; currNT++; } } // System.err.printf("source: %s\n", result); return result; }
private BilingualRule getRuleWithSpans(HyperEdge edge, HGNode head) { Rule edgeRule = edge.getRule(); // System.err.printf("EdgeRule: %s\n", edgeRule); if (!(edgeRule instanceof BilingualRule)) { // System.err.println("edge rule is not a bilingual rule"); return null; } int headLabel = getLabelWithSpan(head); // System.err.printf("Head label: %s\n", headLabel); // if (edge.getAntNodes() != null) { // for (HGNode n : edge.getAntNodes()) // System.err.printf("> %s\n", getLabelWithSpan(n)); // } int[] source = getNewSource(nodeHasGoalSymbol(head), edge); // if this would be unary abstract, getNewSource will be null if (source == null) return null; int[] target = getNewTargetFromSource(source); BilingualRule result = new BilingualRule( headLabel, source, target, edgeRule.getFeatureScores(), edgeRule.getArity()); // System.err.printf("new rule is %s\n", result); return result; }
public double finalTransitionLogP(HyperEdge edge, int spanStart, int spanEnd, int sentID) { return finalTransitionLogP( edge.getAntNodes().get(0), spanStart, spanEnd, edge.getSourcePath(), sentID); }
public double transitionLogP(HyperEdge edge, int spanStart, int spanEnd, int sentID) { return transitionLogP( edge.getRule(), edge.getAntNodes(), spanStart, spanEnd, edge.getSourcePath(), sentID); }