'Return all groups classified by application (module category), as a list::
[(app, kind, groups), ...],
where ``app`` and ``groups`` are recordsets, and ``kind`` is either
``\'boolean\'`` or ``\'selection\'``. Applications are given in sequence
order.  If ``kind`` is ``\'selection\'``, ``groups`` are given in
reverse implication order.'

@api.model
def get_groups_by_application(self):

    def linearize(app, gs):
        order = {g: len((g.trans_implied_ids & gs)) for g in gs}
        if (len(set(order.itervalues())) == len(gs)):
            return (app, 'selection', gs.sorted(key=order.get))
        else:
            return (app, 'boolean', gs)
    (by_app, others) = (defaultdict(self.browse), self.browse())
    for g in self.get_application_groups([]):
        if g.category_id:
            by_app[g.category_id] += g
        else:
            others += g
    res = []
    for (app, gs) in sorted(by_app.iteritems(), key=(lambda (a, _): (a.sequence or 0))):
        res.append(linearize(app, gs))
    if others:
        res.append((self.env['ir.module.category'], 'boolean', others))
    return res
