def besteval(self, reflinks, cache=None): ''' sub-oracle ''' if cache is None: cache = {} sig = (self.step, self.rank) if sig in cache: return cache[sig] if self.action == 0: s = DepVal() t = self.tree() else: h = self.headidx s = -1 t = None for ((left, right), action, _) in self.backptrs: m = left.headidx if action == 1 else right.headidx this = 1 if (m in reflinks and reflinks[m] == h) else 0 thistot = 1 if (m in reflinks) else 0 lefteval, lefttree = left.besteval(reflinks, cache) righteval, righttree = right.besteval(reflinks, cache) thiseval = DepVal(yes=this, tot=thistot) + lefteval + righteval if thiseval > s: s = thiseval t = DepTree.combine(lefttree, righttree, action) cache[sig] = s, t return s, t
def tree(self): '''alternatively: simulate actions''' (children, action, _) = self.backptrs[0] if children is None: return DepTree(self.i) # SHIFT else: left, right = children # REDUCE return DepTree.combine(left.tree(), right.tree(), action)
def tree(self): '''alternatively: simulate actions''' (children, action, _) = self.backptrs[0] if children is None: if FLAGS.pretag and action[0] == -2: return DepTree(self.i, action[2]) elif FLAGS.shifttag and action[0] == 0: return DepTree(self.i, action[2]) else: return DepTree( self.i, action[1]) # yang: SHIFT tag (changes tag in deptree) else: left, right = children # REDUCE return DepTree.combine(left.tree(), right.tree(), action)