private void closeRulesUnderMax(UnaryRule ur) { for (int i = 0, isz = closedRulesWithChild[ur.parent].size(); i < isz; i++) { UnaryRule pr = closedRulesWithChild[ur.parent].get(i); for (int j = 0, jsz = closedRulesWithParent[ur.child].size(); j < jsz; j++) { UnaryRule cr = closedRulesWithParent[ur.child].get(j); UnaryRule resultR = new UnaryRule(pr.parent, cr.child, pr.score + cr.score + ur.score); relaxRule(resultR); /* ----- No longer need to maintain unary rule backpointers if (relaxRule(resultR)) { if (resultR.parent != ur.parent) { backTrace.put(resultR, new Integer(ur.parent)); } else { backTrace.put(resultR, new Integer(ur.child)); } } -------- */ } } }
protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) { String parentString = stateIndex.get(rule.parent); String childString = stateIndex.get(rule.child); if (isSyntheticState(parentString)) { String topcat = getTopCategoryOfSyntheticState(parentString); TransducerGraph graph = getGraphFromMap(graphs, topcat); Double output = new Double(smartNegate(rule.score())); graph.addArc(graph.getStartNode(), parentString, childString, output); return true; } else if (isSyntheticState(childString)) { // need to add Arc from synthetic state to endState TransducerGraph graph = getGraphFromMap(graphs, parentString); Double output = new Double(smartNegate(rule.score())); graph.addArc(childString, parentString, END, output); // parentString should the the same as endState graph.setEndNode(parentString); return true; } else { return false; } }
/** * Writes out data from this Object. * @param w Data is written to this Writer */ public void writeData(Writer w) { PrintWriter out = new PrintWriter(w); // all lines have one rule per line for (UnaryRule ur : this) { out.println(ur.toString(index)); } out.flush(); }
/** * Populates data in this UnaryGrammar from a character stream. * * @param in The Reader the grammar is read from. * @throws IOException If there is a reading problem */ public void readData(BufferedReader in) throws IOException { String line; int lineNum = 1; // all lines have one rule per line line = in.readLine(); while (line != null && line.length() > 0) { try { addRule(new UnaryRule(line, index)); } catch (Exception e) { throw new IOException("Error on line " + lineNum); } lineNum++; line = in.readLine(); } purgeRules(); }
out.println(rI.next().toString(index)); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = ruleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = closedRuleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index));
UnaryRule ur = rules.get(0); double localTreeScore = ur.score();
/** Create all the array variables, and put in A -> A UnaryRules to feed * the closure algorithm. They then get deleted later. */ @SuppressWarnings("unchecked") private void init() { int numStates = index.size(); coreRules = Generics.newHashMap(); rulesWithParent = new List[numStates]; rulesWithChild = new List[numStates]; closedRulesWithParent = new List[numStates]; closedRulesWithChild = new List[numStates]; bestRulesUnderMax = Generics.newHashMap(); // backTrace = Generics.newHashMap(); for (int s = 0; s < numStates; s++) { rulesWithParent[s] = new ArrayList<>(); rulesWithChild[s] = new ArrayList<>(); closedRulesWithParent[s] = new ArrayList<>(); closedRulesWithChild[s] = new ArrayList<>(); UnaryRule selfR = new UnaryRule(s, s, 0.0); relaxRule(selfR); } }
/** * Writes out data from this Object. * @param w Data is written to this Writer */ public void writeData(Writer w) { PrintWriter out = new PrintWriter(w); // all lines have one rule per line for (UnaryRule ur : this) { out.println(ur.toString(index)); } out.flush(); }
protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) { String parentString = stateIndex.get(rule.parent); String childString = stateIndex.get(rule.child); if (isSyntheticState(parentString)) { String topcat = getTopCategoryOfSyntheticState(parentString); TransducerGraph graph = getGraphFromMap(graphs, topcat); Double output = new Double(smartNegate(rule.score())); graph.addArc(graph.getStartNode(), parentString, childString, output); return true; } else if (isSyntheticState(childString)) { // need to add Arc from synthetic state to endState TransducerGraph graph = getGraphFromMap(graphs, parentString); Double output = new Double(smartNegate(rule.score())); graph.addArc(childString, parentString, END, output); // parentString should the the same as endState graph.setEndNode(parentString); return true; } else { return false; } }
int firstChild = stateIndex.indexOf(tree.children()[0].label().value()); if (tree.numChildren() == 1) { UnaryRule ur = new UnaryRule(parent, firstChild); double score = SloppyMath.max(ug.scoreRule(ur), -10000.0) + validateBinarizedTree(tree.children()[0], start); double bound = iScore[start][start + tree.yield().size()][parent];
/** * Writes out data from this Object. * @param w Data is written to this Writer */ public void writeData(Writer w) { PrintWriter out = new PrintWriter(w); // all lines have one rule per line for (UnaryRule ur : this) { out.println(ur.toString(index)); } out.flush(); }
protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) { String parentString = (String) stateNumberer.object(rule.parent); String childString = (String) stateNumberer.object(rule.child); if (isSyntheticState(parentString)) { String topcat = getTopCategoryOfSyntheticState(parentString); TransducerGraph graph = getGraphFromMap(graphs, topcat); Double output = new Double(smartNegate(rule.score())); graph.addArc(graph.getStartNode(), parentString, childString, output); return true; } else if (isSyntheticState(childString)) { // need to add Arc from synthetic state to endState TransducerGraph graph = getGraphFromMap(graphs, parentString); Double output = new Double(smartNegate(rule.score())); graph.addArc(childString, parentString, END, output); // parentString should the the same as endState graph.setEndNode(parentString); return true; } else { return false; } }
if (source.equals(startNode)) { UnaryRule ur = new UnaryRule(newStateIndex.addToIndex(target), newStateIndex.addToIndex(inputString), smartNegate(output)); unaryRules.add(ur); } else if (inputString.equals(END) || inputString.equals(EPSILON)) { UnaryRule ur = new UnaryRule(newStateIndex.addToIndex(target), newStateIndex.addToIndex(source), smartNegate(output)); unaryRules.add(ur); } else {
/** * Writes out data from this Object. * @param w Data is written to this Writer */ public void writeData(Writer w) { PrintWriter out = new PrintWriter(w); // all lines have one rule per line for (UnaryRule ur : this) { out.println(ur.toString(index)); } out.flush(); }
protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) { String parentString = stateIndex.get(rule.parent); String childString = stateIndex.get(rule.child); if (isSyntheticState(parentString)) { String topcat = getTopCategoryOfSyntheticState(parentString); TransducerGraph graph = getGraphFromMap(graphs, topcat); Double output = new Double(smartNegate(rule.score())); graph.addArc(graph.getStartNode(), parentString, childString, output); return true; } else if (isSyntheticState(childString)) { // need to add Arc from synthetic state to endState TransducerGraph graph = getGraphFromMap(graphs, parentString); Double output = new Double(smartNegate(rule.score())); graph.addArc(childString, parentString, END, output); // parentString should the the same as endState graph.setEndNode(parentString); return true; } else { return false; } }
@Override protected void tallyInternalNode(Tree lt, double weight) { if (lt.children().length == 1) { UnaryRule ur = new UnaryRule(stateIndex.addToIndex(lt.label().value()), stateIndex.addToIndex(lt.children()[0].label().value())); symbolCounter.incrementCount(stateIndex.get(ur.parent), weight); unaryRuleCounter.incrementCount(ur, weight); unaryRules.add(ur); } else { BinaryRule br = new BinaryRule(stateIndex.addToIndex(lt.label().value()), stateIndex.addToIndex(lt.children()[0].label().value()), stateIndex.addToIndex(lt.children()[1].label().value())); symbolCounter.incrementCount(stateIndex.get(br.parent), weight); binaryRuleCounter.incrementCount(br, weight); binaryRules.add(br); } }
out.println(rI.next().toString(index)); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = ruleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = closedRuleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index));
protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) { String parentString = stateIndex.get(rule.parent); String childString = stateIndex.get(rule.child); if (isSyntheticState(parentString)) { String topcat = getTopCategoryOfSyntheticState(parentString); TransducerGraph graph = getGraphFromMap(graphs, topcat); Double output = new Double(smartNegate(rule.score())); graph.addArc(graph.getStartNode(), parentString, childString, output); return true; } else if (isSyntheticState(childString)) { // need to add Arc from synthetic state to endState TransducerGraph graph = getGraphFromMap(graphs, parentString); Double output = new Double(smartNegate(rule.score())); graph.addArc(childString, parentString, END, output); // parentString should the the same as endState graph.setEndNode(parentString); return true; } else { return false; } }
int childIndex = stateIndex.indexOf(state(child, j)); double score = betas[i][j] - Math.log(stateTotal[i]); UnaryRule ur = new UnaryRule(parentIndex, childIndex, score); ug.addRule(ur);
out.println(rI.next().toString(index)); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = ruleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index)); for (Iterator<UnaryRule> rI = closedRuleIteratorByParent(i); rI.hasNext(); ) { out.print(" "); out.println(rI.next().toString(index));