def group_results(triplet_list): # for each path, build a list of path_type: value article_groups = {} for art, art_type, count in triplet_list: zeroed_row = Counter({ 'full': 0, 'abstract': 0, 'digest': 0, }) group = article_groups.get(art, [zeroed_row]) # every article always has a zeroed result group.append(Counter({art_type: count})) article_groups[art] = group # take our list of Counter objects and count them up def update(a,b): # https://docs.python.org/2/library/collections.html#collections.Counter.update a.update(b) return a return {utils.enplumpen(art): reduce(update, group) for art, group in article_groups.items()}
def group_results(triplet_list): # for each path, build a list of path_type: value article_groups = {} for art, art_type, count in triplet_list: zeroed_row = Counter({ 'full': 0, 'abstract': 0, 'digest': 0, }) group = article_groups.get( art, [zeroed_row]) # every article always has a zeroed result group.append(Counter({art_type: count})) article_groups[art] = group # take our list of Counter objects and count them up def update(a, b): # https://docs.python.org/2/library/collections.html#collections.Counter.update a.update(b) return a return { utils.enplumpen(art): reduce(update, group) for art, group in article_groups.items() }
def test_enplumpen(self): self.assertEqual("10.7554/eLife.01234", utils.enplumpen("e01234"))