def count_citations_by_annotation(graph: BELGraph, annotation: str) -> Mapping[str, typing.Counter[str]]:
citations = defaultdict(lambda: defaultdict(set))<EOL>for u, v, data in graph.edges(data=True):<EOL><INDENT>if not edge_has_annotation(data, annotation) or CITATION not in data:<EOL><INDENT>continue<EOL><DEDENT>k = data[ANNOTATIONS][annotation]<EOL>citations[k][u, v].add((data[CITATION][CITATION_TYPE], data[CITATION][CITATION_REFERENCE].strip()))<EOL><DEDENT>return {k: Counter(itt.chain.from_iterable(v.values())) for k, v in citations.items()}<EOL>
Group the citation counters by subgraphs induced by the annotation.

    :param graph: A BEL graph
    :param annotation: The annotation to use to group the graph
    :return: A dictionary of Counters {subgraph name: Counter from {citation: frequency}}