public HyperEdge Allocate(HyperVertex p, HyperVertex c) { //return new HyperEdge(p, c); var e = GetNext(); e.Set(p, c); return e; }
public HyperEdge Allocate(HyperVertex p, HyperVertex w, double[] terminalScores, double[] terminalExpects) { //return new HyperEdge(p, w, terminalScores, terminalExpects); var e = GetNext(); e.Set(p, w, terminalScores, terminalExpects); return e; }
public HyperEdge Allocate(HyperVertex p, HyperVertex c, double[][] unaryScores, double[][] unaryExpects) { //return new HyperEdge(p, c, unaryScores, unaryExpects); var e = GetNext(); e.Set(p, c, unaryScores, unaryExpects); return e; }
public HyperEdge Allocate(HyperVertex p, HyperVertex l, HyperVertex r, double[][][] binaryScores, double[][][] binaryExpects) { //return new HyperEdge(p, l, r, binaryScores, binaryExpects); var e = GetNext(); e.Set(p, l, r, binaryScores, binaryExpects); return e; }
private HyperVertex GetNext(int subtagCapacity) { HyperVertex v; if (next [subtagCapacity] >= pools [subtagCapacity].Count) { v = new HyperVertex (subtagCapacity); pools [subtagCapacity].Add (v); } else { v = pools [subtagCapacity] [next [subtagCapacity]]; } next [subtagCapacity] += 1; v.Clear(); return v; }
public HyperEdge(HyperVertex p, HyperVertex c) { Set (p, c); }
public HyperEdge(HyperVertex p, HyperVertex c, double[][] unaryScores, double[][] unaryExpects) { Set (p, c, unaryScores, unaryExpects); }
public void Set(HyperVertex p, HyperVertex c) { TYPE = ETYPE.DUMMY; to = p; //from.Add(c); from0 = c; from1 = null; p.AddIncomingLink (this); c.AddOutgoingLink (this); posteriorScore = double.NegativeInfinity; }
public void Set(HyperVertex p, HyperVertex c, double[][] unaryScores, double[][] unaryExpects) { TYPE = ETYPE.UNARY; this.unaryScores = unaryScores; this.unaryExpects = unaryExpects; to = p; from0 = c; from1 = null; p.AddIncomingLink (this); c.AddOutgoingLink (this); posteriorScore = double.NegativeInfinity; }
public HyperEdge(HyperVertex p, HyperVertex w, double[] terminalScores, double[] terminalExpects) { Set (p, w, terminalScores, terminalExpects); }
public void Set(HyperVertex p, HyperVertex w, double[] terminalScores, double[] terminalExpects) { TYPE = ETYPE.TERMINAL; this.terminalScores = terminalScores; this.terminalExpects = terminalExpects; to = p; from0 = w; from1 = null; p.AddIncomingLink (this); w.AddOutgoingLink (this); posteriorScore = double.NegativeInfinity; }
public HyperEdge(HyperVertex p, HyperVertex l, HyperVertex r, double[][][] binaryScores, double[][][] binaryExpects) { Set (p, l, r, binaryScores, binaryExpects); }
public void Clear() { to = null; from0 = null; from1 = null; next = null; TYPE = ETYPE.NULL; }
private void BuildHyperGraph( PhrasalNode node, HyperGraph g, out HyperVertex v) { v = null; if (node == null) { return; } if (node.Children.Count == 0) { int pt = tagset.GetPTID(node.Tag); int wid = vocab.GetId(node.Lex, node.Start == 0); HyperVertex wv = new HyperVertex(true, wid, 1); HyperVertex pv = new HyperVertex(false, pt, rules.GetSubTagCount(pt)); HyperEdge pe = new HyperEdge(pv, wv, rules.GetTerminalRuleScores(pt, wid), rules.GetTerminalPosteriorCounts(pt, wid)); g.Es.Add(pe); g.Vs.Add(wv); g.Vs.Add(pv); v = pv; return; } else if (node.Children.Count == 1) { HyperVertex cv; BuildHyperGraph(node.Children [0], g, out cv); int pt = tagset.GetID(node.Tag); HyperVertex pv = new HyperVertex(false, pt, rules.GetSubTagCount(pt)); HyperEdge pe = new HyperEdge( pv, cv, rules.GetRuleScores(pt, cv.tag), rules.GetPosteriorCounts(pt, cv.tag)); g.Es.Add(pe); g.Vs.Add(pv); v = pv; return; } else if (node.Children.Count == 2) { HyperVertex lv; HyperVertex rv; BuildHyperGraph(node.Children [0], g, out lv); BuildHyperGraph(node.Children [1], g, out rv); int pt = tagset.GetID(node.Tag); HyperVertex pv = new HyperVertex(false, pt, rules.GetSubTagCount(pt)); HyperEdge pe = new HyperEdge(pv, lv, rv, rules.GetRuleScores(pv.tag, lv.tag, rv.tag), rules.GetPosteriorCounts(pv.tag, lv.tag, rv.tag)); g.Es.Add(pe); g.Vs.Add(pv); v = pv; return; } else { throw new Exception("tree node can only have at most 2 children"); } }
private static void MatchLexicon( LAPCFGrammar table, HyperCell cell, int wid, HyperEdgePool epool, HyperVertexPool vpool, int[] tagCapacity, bool[] allowedTags, double[] tagProbs, bool isRoot) { var tv = new HyperVertex (true, wid, 1); var trules = table.trules [wid]; foreach (var rule in trules) { if (rule == null) { break; } if (rule.tag == table.ROOTID && !isRoot) { continue; } if (allowedTags != null && !allowedTags[rule.tag]) { continue; } var xrule = rule; if (tagProbs != null) { var xprob = tagProbs[rule.tag]; if (double.IsNegativeInfinity(xprob)) { continue; } xrule = rule.Clone(); for (int i = 0; i < xrule.scores.Length; ++i) { if (!double.IsNegativeInfinity(xrule.scores[i])) { xrule.scores[i] += xprob; } } } var cap = tagCapacity == null ? -1 : tagCapacity [rule.tag]; cell.l1v [rule.tag] = vpool.Allocate (false, rule.tag, table.GetSubTagCount (rule.tag), cap); epool.Allocate (cell.l1v [rule.tag], tv, xrule.scores, null); if (isRoot && rule.tag != table.ROOTID) { continue; } cell.l2v [rule.tag] = vpool.Allocate (false, rule.tag, table.GetSubTagCount (rule.tag), cap); epool.Allocate (cell.l2v [rule.tag], cell.l1v [rule.tag]); } }
private PhrasalNode ExtractViterbiParse(HyperVertex v, int subtag, TagSet tagSet) { if (v == null || v.TYPE == VTYPE.TERMINAL) { return null; } PhrasalNode node = new PhrasalNode(); node.Tag = tagSet.GetTagString(v.tag); var bestEdge = v.traces[subtag].edge; if (bestEdge == null) { return node; } switch (bestEdge.TYPE) { case ETYPE.BINARY: var l = ExtractViterbiParse(bestEdge.from0, v.traces[subtag].subtag0, tagSet); var r = ExtractViterbiParse(bestEdge.from1, v.traces[subtag].subtag1, tagSet); node.Children.Add(l); node.Children.Add(r); l.Parent = node; r.Parent = node; break; case ETYPE.UNARY: var c = ExtractViterbiParse(bestEdge.from0, v.traces[subtag].subtag0, tagSet); node.Children.Add(c); c.Parent = node; break; case ETYPE.TERMINAL: break; case ETYPE.DUMMY: node = ExtractViterbiParse(bestEdge.from0, v.traces[subtag].subtag0, tagSet); break; default: throw new Exception("unknown edge type!"); } return node; }
public void Set(HyperVertex p, HyperVertex l, HyperVertex r, double[][][] binaryScores, double[][][] binaryExpects) { TYPE = ETYPE.BINARY; this.binaryScores = binaryScores; this.binaryExpects = binaryExpects; to = p; from0 = l; from1 = r; p.AddIncomingLink (this); l.AddOutgoingLink (this); r.AddOutgoingLink (this); posteriorScore = double.NegativeInfinity; }