Exemplo n.º 1
0
    def collocs(self, cattr='-', csortfn='m', cbgrfns='mt', cfromw=-5, ctow=5, cminfreq=5, cminbgr=3, max_lines=0):
        statdesc = {'t': translate('T-score'),
                    'm': translate('MI'),
                    '3': translate('MI3'),
                    'l': translate('log likelihood'),
                    's': translate('min. sensitivity'),
                    'p': translate('MI.log_f'),
                    'r': translate('relative freq. [%]'),
                    'f': translate('absolute freq.'),
                    'd': translate('logDice')
                    }
        items = []
        colls = manatee.CollocItems(self, cattr, csortfn, cminfreq, cminbgr,
                                    cfromw, ctow, max_lines)
        qfilter = '%%s%i %i 1 [%s="%%s"]' % (cfromw, ctow, cattr)
        i = 0
        while not colls.eos():
            if 0 < max_lines < i:
                break
            items.append(dict(
                str=colls.get_item(),
                freq=colls.get_cnt(),
                Stats=[{'s': '%.3f' % colls.get_bgr(s)} for s in cbgrfns],
                pfilter=qfilter % ('P', escape(self.import_string(colls.get_item()))),
                nfilter=qfilter % ('N', escape(self.import_string(colls.get_item())))
            ))
            colls.next()
            i += 1

        head = [{'n': ''}, {'n': 'Freq', 's': 'f'}] + \
            [{'n': statdesc.get(s, s), 's': s} for s in cbgrfns]
        return dict(Head=head, Items=items)
Exemplo n.º 2
0
    def collocs(self,
                cattr='-',
                csortfn='m',
                cbgrfns='mt',
                cfromw=-5,
                ctow=5,
                cminfreq=5,
                cminbgr=3,
                from_idx=0,
                max_lines=50):
        statdesc = {
            't': 'T-score',
            'm': 'MI',
            '3': 'MI3',
            'l': 'log likelihood',
            's': 'min. sensitivity',
            'p': 'MI.log_f',
            'r': 'relative freq. [%]',
            'f': 'absolute freq.',
            'd': 'logDice',
        }

        items = []
        colls = manatee.CollocItems(self, cattr, csortfn, cminfreq, cminbgr,
                                    cfromw, ctow, 2**29)
        qfilter = '%%s%i %i 1 [%s="%%s"]' % (cfromw, ctow, cattr)
        i = 0
        while not colls.eos():
            if from_idx <= i < from_idx + max_lines:
                items.append({
                    'str':
                    colls.get_item(),
                    'freq':
                    colls.get_cnt(),
                    'Stats': [{
                        's': '%.3f' % colls.get_bgr(s)
                    } for s in cbgrfns],
                    'pfilter':
                    qfilter %
                    ('P', escape(self.import_string(colls.get_item()))),
                    'nfilter':
                    qfilter %
                    ('N', escape(self.import_string(colls.get_item())))
                })
            colls.next()
            i += 1

        head = [{'n': ''}, {'n': 'Freq', 's': 'f'}] \
            + [{'n': statdesc.get(s, s), 's': s} for s in cbgrfns]
        return {
            'Head': head,
            'Items': self.add_block_items(items),
            'Total': i,
            'TotalPages': int(math.ceil(i / float(max_lines)))
        }