def _mergeGraph(A, B):
    """Return the merged graph of A and B."""
    for key, val in B.nodes.items():
        if A.has_node(key):
            A.nodes[key]['count'] += val['count']
            for i in range(len(val['pos'])):
                if val['pos'][i] not in A.nodes[key]['pos']:
                    A.nodes[key]['pos'].append(val['pos'][i])
                    A.nodes[key]['lpos'].append(val['lpos'][i])
                    A.nodes[key]['func'].append(val['func'][i])
                    A.nodes[key]['surface'].append(val['surface'][i])
                    A.nodes[key]['yomi'].append(val['yomi'][i])
                    if 'depth' in A.nodes[key]:
                        A.nodes[key]['depth'].append(val['depth'][i])
        else:
            A.add_node(key, **val)
    for key, val in B.edges.items():
        if A.has_edge(*key):
            A.edges[key[0], key[1]]['weight'] += val['weight']
        else:
            A.add_edge(*key, **val)
    return A
