Exemplo n.º 1
0
 def __init__(self):
     PrintAbsorptionCountsByBranching2.__bases__[0].__init__(self)
     self.e0 = CountDict()
     self.e1 = CountDict()
     self.e2 = CountDict()
     self.e3 = CountDict()
     
     self.e0_examples = defaultdict(FixedSizeList)
     self.e1_examples = defaultdict(FixedSizeList)
     self.e2_examples = defaultdict(FixedSizeList)
     self.e3_examples = defaultdict(FixedSizeList)
Exemplo n.º 2
0
class PrintCommaCountsByBranching(FixedTgrep(r'{, $ /.+/} > /.+/')):
    '''Prints comma occurrence counts by descending frequency together with the rule used.'''
    def __init__(self):
        PrintCommaCountsByBranching.__bases__[0].__init__(self)
        self.envs = CountDict()
        
    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 match_generator(self, deriv, expr):
        return find_all(deriv, expr)
    
    def match_callback(self, match_node, bundle):
        is_left_child = match_node.parent.lch is match_node
        if is_left_child:
            self.envs[ (str(match_node.cat), str(match_node.parent.rch.cat), str(match_node.parent.cat)) ] += 1
        else:                                                             
            self.envs[ (str(match_node.parent.lch.cat), str(match_node.cat), str(match_node.parent.cat)) ] += 1
Exemplo n.º 3
0
class PrintCommaCountsByBranching(FixedTgrep(r"{, $ /.+/} > /.+/")):
    """Prints comma occurrence counts by descending frequency together with the rule used."""

    def __init__(self):
        PrintCommaCountsByBranching.__bases__[0].__init__(self)
        self.envs = CountDict()

    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 match_generator(self, deriv, expr):
        return find_all(deriv, expr)

    def match_callback(self, match_node, bundle):
        is_left_child = match_node.parent.lch is match_node
        if is_left_child:
            self.envs[(str(match_node.cat), str(match_node.parent.rch.cat), str(match_node.parent.cat))] += 1
        else:
            self.envs[(str(match_node.parent.lch.cat), str(match_node.cat), str(match_node.parent.cat))] += 1
Exemplo n.º 4
0
 def __init__(self):
     Filter.__init__(self)
     self.freqs = CountDict()
Exemplo n.º 5
0
 def __init__(self):
     Filter.__init__(self)
     self.counter = CountDict()
Exemplo n.º 6
0
 def __init__(self):
     DumpRules.__bases__[0].__init__(self)
     self.rules = CountDict()
Exemplo n.º 7
0
 def __init__(self):
     self.counts = CountDict()
     self.total = 0
Exemplo n.º 8
0
 def __init__(self):
     CountRuleOccurrencesByType.__bases__[0].__init__(self)
     self.counts = CountDict()
Exemplo n.º 9
0
 def __init__(self):
     PrintCommaCountsByBranching.__bases__[0].__init__(self)
     self.envs = CountDict()
Exemplo n.º 10
0
 def __init__(self):
     Filter.__init__(self)
     self.envs = CountDict()
Exemplo n.º 11
0
 def __init__(self):
     PrintCommaCountsByBranching.__bases__[0].__init__(self)
     self.envs = CountDict()