예제 #1
0
def compare_partial_colexifications():
    alms = get_alignments()
    G = nx.Graph()
    for k in alms:
        concept = alms[k, "concept"]
        morphemes = split_tokens(alms[k, "tokens"])
        doculect = alms[k, "doculect"]
        if concept not in G.node:
            G.add_node(concept, bipartite=0)

        for m in morphemes:
            idf = "".join(m) + "/" + doculect
            if idf not in G.node:
                G.add_node(idf, bipartite=1)
            G.add_edge(concept, idf)
    print("printing now")
    save_network("bipartite.gml", G)
    nodes = {n for n, d in G.nodes(data=True) if d["bipartite"] == 0}
    G2 = nx.bipartite.collaboration_weighted_projected_graph(G, nodes)
    save_network("projected.gml", G2)
    return G
예제 #2
0
from pyburmish.phonology import *
import networkx as nx
from networkx import bipartite as bt
from pyclics.utils import save_network

table, *rest = initials_and_rhymes('Lashi')

G = nx.Graph()
for k, v in table.items():
    G.add_node(' '.join(k), bipartite=0)
    for val, occ in v.items():
        if not val in G.node:
            G.add_node(val, bipartite=1)
        G.add_edge(' '.join(k), val, weight=len(occ))

initials = {n for n, d in G.nodes(data=True) if d['bipartite'] == 1}
finals = {n for n, d in G.nodes(data=True) if d['bipartite'] == 0}

I = bt.projection.collaboration_weighted_projected_graph(G, initials)
F = bt.projection.collaboration_weighted_projected_graph(G, finals)

save_network('initials.gml', I)
save_network('finals.gml', F)
save_network('bipartite.gml', G)