def build_network_graph()

in amazon_comprehend_events_tutorial/notebooks/events_graph.py [0:0]


def build_network_graph(nodelist, edgelist, drop_isolates=True):
    G = nx.Graph()
    # Iterate over triggers and entity mentions.
    for mention_id, tag, extent, score, mtype in nodelist:
        G.add_node(
            mention_id,
            label=extent,
            tag=tag,
            group=mtype,
            size=PROPERTY_MAP[mtype]['size'],
            color=COLOR_MAP[tag],
            shape=PROPERTY_MAP[mtype]['shape']
            )
    # Iterate over argument role assignments
    if edgelist:
        for n1_id, n2_id, role, score, etype in edgelist:
            label = role if etype == "argument" else "coref"
            G.add_edges_from(
                [(n1_id, n2_id)],
                label=role,
                weight=score*100,
                color="grey"
            )
    # Drop mentions that don't participate in events
    if len(edgelist) > 0 and drop_isolates:
        G.remove_nodes_from(list(nx.isolates(G)))
    return G