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)); } } -------- */ } } }
/** * 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(); }
/** 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); } }
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];
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 {
@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); } }
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);
int firstChild = stateIndex.indexOf(tree.children()[0].label().value()); if (tree.numChildren() == 1) { UnaryRule ur = new UnaryRule(parent, firstChild);
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)); } } -------- */ } } }
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)); } } -------- */ } } }
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)); } } -------- */ } } }
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)); } } -------- */ } } }
/** 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() { coreRules = new HashMap<UnaryRule,UnaryRule>(); rulesWithParent = new List[numStates]; rulesWithChild = new List[numStates]; closedRulesWithParent = new List[numStates]; closedRulesWithChild = new List[numStates]; bestRulesUnderMax = new HashMap<UnaryRule,UnaryRule>(); // backTrace = new HashMap<UnaryRule,Integer>(); for (int s = 0; s < numStates; s++) { rulesWithParent[s] = new ArrayList<UnaryRule>(); rulesWithChild[s] = new ArrayList<UnaryRule>(); closedRulesWithParent[s] = new ArrayList<UnaryRule>(); closedRulesWithChild[s] = new ArrayList<UnaryRule>(); UnaryRule selfR = new UnaryRule(s, s, 0.0); relaxRule(selfR); } }
/** * 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(); }
/** 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); } }
/** 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<UnaryRule>(); rulesWithChild[s] = new ArrayList<UnaryRule>(); closedRulesWithParent[s] = new ArrayList<UnaryRule>(); closedRulesWithChild[s] = new ArrayList<UnaryRule>(); UnaryRule selfR = new UnaryRule(s, s, 0.0); relaxRule(selfR); } }
@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); } }
@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); } }
@Override protected void tallyInternalNode(Tree lt, double weight) { if (lt.children().length == 1) { UnaryRule ur = new UnaryRule(stateIndex.indexOf(lt.label().value(), true), stateIndex.indexOf(lt.children()[0].label().value(), true)); symbolCounter.incrementCount(stateIndex.get(ur.parent), weight); unaryRuleCounter.incrementCount(ur, weight); unaryRules.add(ur); } else { BinaryRule br = new BinaryRule(stateIndex.indexOf(lt.label().value(), true), stateIndex.indexOf(lt.children()[0].label().value(), true), stateIndex.indexOf(lt.children()[1].label().value(), true)); symbolCounter.incrementCount(stateIndex.get(br.parent), weight); binaryRuleCounter.incrementCount(br, weight); binaryRules.add(br); } }
@Override protected void tallyInternalNode(Tree lt) { Rule r; if (lt.children().length == 1) { r = new UnaryRule(stateNumberer.number(lt.label().value()), stateNumberer.number(lt.children()[0].label().value())); } else { r = new BinaryRule(stateNumberer.number(lt.label().value()), stateNumberer.number(lt.children()[0].label().value()), stateNumberer.number(lt.children()[1].label().value())); } tallyRule(r, weight); }