tuw_nlp/graph/utils.py
def sen_to_graph(sen):
    """convert dependency-parsed stanza Sentence to nx.DiGraph"""
    G = nx.DiGraph()
    for word in sen.to_dict():
        if isinstance(word['id'], (list, tuple)):
            # token representing an mwe, e.g. "vom" ~ "von dem"
            continue
        G.add_node(word['id'], **word)
        G.add_edge(word['head'], word['id'], deprel=word['deprel'])
    return G
convert dependency-parsed stanza Sentence to nx.DiGraph
convert dependency-parsed stanza Sentence to nx.DiGraph
convert dependency - parsed stanza Sentence to nx . DiGraph
def sen_to_graph(sen):
    G = nx.DiGraph()
    for word in sen.to_dict():
        if isinstance(word['id'], (list, tuple)):
            continue
        G.add_node(word['id'], **word)
        G.add_edge(word['head'], word['id'], deprel=word['deprel'])
    return G
def sen_to_graph ( sen ) : G = nx . DiGraph ( ) for word in sen . to_dict ( ) : if isinstance ( word [ 'id' ] , ( list , tuple ) ) : continue G . add_node ( word [ 'id' ] , ** word ) G . add_edge ( word [ 'head' ] , word [ 'id' ] , deprel = word [ 'deprel' ] ) return G
convert dependency-parsed stanza Sentence to nx.DiGraph
convert dependency - parsed stanza Sentence to nx . DiGraph
"""convert dependency-parsed stanza Sentence to nx.DiGraph""" # token representing an mwe, e.g. "vom" ~ "von dem"
sen