def output(self): headings = ("(%s ,) %s -> %s", "(, %s) %s -> %s", "%s (%s ,) -> %s", "%s (, %s) -> %s") for index, heading in enumerate(headings): env_hash = getattr(self, 'e%d' % index) print heading % ('X', 'Y', 'Z') print "-" * len(heading) examples_hash = getattr(self, 'e%d_examples' % index) for (l, r, p), f in sorted_by_value_desc(env_hash): triple = heading % (l, r, p) print "% 10d [%28s] %-60s %s" % (f, analyse(C(l), C(r), C(p)), triple, ' '.join(examples_hash[(l, r, p)])) if (index == 0 and (l, r, p) in self.e3 and self.e3[(l, r, p)] <= f): alt_triple = headings[3] % (l, r, p) alt_freq = self.e3[(l, r, p)] print "* % 8d%32s%-60s %s" % (alt_freq, " "*32, alt_triple, ' '.join(self.e3_examples[(l, r, p)])) elif (index == 3 and (l, r, p) in self.e0 and self.e0[(l, r, p)] <= f): alt_triple = headings[0] % (l, r, p) alt_freq = self.e0[(l, r, p)] print "* % 8d%32s%-60s %s" % (alt_freq, " "*32, alt_triple, ' '.join(self.e0_examples[(l, r, p)]))
def __init__(self, focus, sib, parent): Filter.__init__(self) self.focus = C(focus) self.sib = C(sib) self.parent = C(parent) self.sib_as_left = set() self.sib_as_right = set()
def accept_leaf(self, leaf): if leaf.cat == C(','): was_left_child = leaf.parent.lch is leaf if was_left_child: environment = map(lambda e: str(e.cat), [ leaf, leaf.parent.rch, leaf.parent ]) else: environment = map(lambda e: str(e.cat), [ leaf.parent.lch, leaf, leaf.parent ]) self.envs[ tuple(environment) ] += 1
def accept_leaf(self, leaf): if leaf.cat == C(','): if leaf.parent is None or leaf.parent.parent is None: return was_left_child = leaf.parent.lch is leaf if was_left_child: environment = [self.LEFT] + map(lambda e: str(e.cat), [ self.rightmost(leaf.parent.parent.lch), leaf.parent, leaf.parent.parent ]) else: if leaf.parent.parent.rch is None: return environment = [self.RIGHT] + map(lambda e: str(e.cat), [ leaf.parent, self.leftmost(leaf.parent.parent.rch), leaf.parent.parent ]) self.envs[ tuple(environment) ] += 1
def output(self): as_left = {} as_right = {} for (l, r, p), f in self.envs.iteritems(): if l == ',': as_left[(l, r, p)] = f else: as_right[(l, r, p)] = f print ", _ -> _" print "--------" for (l, r, p), f in sorted_by_value_desc(as_left): print "% 10d [%28s] %s %20s -> %s" % (f, analyse(C(l), C(r), C(p)), l, r, p) print "_ , -> _" print "--------" for (l, r, p), f in sorted_by_value_desc(as_right): print "% 10d [%28s] %20s %s -> %s" % (f, analyse(C(l), C(r), C(p)), l, r, p)
def output(self): as_left = {} as_right = {} for (side, l, r, p), f in self.envs.iteritems(): if side == AnalyseAbsorption.LEFT: as_left[ (l, r, p) ] = f elif side == AnalyseAbsorption.RIGHT: as_right[ (l, r, p) ] = f print "(X ,) Y -> Z" print "--------" for (l, r, p), f in sorted_by_value_desc(as_left): print "% 10d [%28s] (%s ,) %s -> %s" % (f, analyse(C(l), C(r), C(p)), l, r, p) print "X (, Y) -> Z" print "--------" for (l, r, p), f in sorted_by_value_desc(as_right): print "% 10d [%28s] %s (, %s) -> %s" % (f, analyse(C(l), C(r), C(p)), l, r, p)