Commit ca4fd62d authored by Alexandre Delanoë's avatar Alexandre Delanoë

Uncompress json

parent e383bad6
...@@ -42,24 +42,26 @@ def filterByBridgeness(G,partition,ids,weight,bridgeness,type,field1,field2): ...@@ -42,24 +42,26 @@ def filterByBridgeness(G,partition,ids,weight,bridgeness,type,field1,field2):
for k, v in partition.items(): for k, v in partition.items():
com_ids[v].append(k) com_ids[v].append(k)
edge_id = 1
for e in G.edges_iter(): for e in G.edges_iter():
s = e[0] s = e[0]
t = e[1] t = e[1]
weight = G[ids[s][1]][ids[t][1]]["weight"] weight = G[ids[s][1]][ids[t][1]]["weight"]
if bridgeness < 0: if bridgeness < 0:
info = { "s": ids[s][1] info = { "source": ids[s][1]
, "t": ids[t][1] , "target": ids[t][1]
, "w": weight , "weight": weight
} }
links.append(info) links.append(info)
else: else:
if partition[s] == partition[t]: if partition[s] == partition[t]:
info = { "s": ids[s][1] info = { "source": ids[s][1]
, "t": ids[t][1] , "target": ids[t][1]
, "w": weight , "weight": weight
} }
links.append(info) links.append(info)
...@@ -82,27 +84,35 @@ def filterByBridgeness(G,partition,ids,weight,bridgeness,type,field1,field2): ...@@ -82,27 +84,35 @@ def filterByBridgeness(G,partition,ids,weight,bridgeness,type,field1,field2):
, reverse=True)[:index]: , reverse=True)[:index]:
#print(c1, c2, link[2]) #print(c1, c2, link[2])
info = {"s": link[0], "t": link[1], "w": link[2]} info = {"source": link[0], "target": link[1], "weight": link[2]}
links.append(info) links.append(info)
B = json_graph.node_link_data(G) B = json_graph.node_link_data(G)
B["links"] = []
B["links"] = links links_id = []
edge_id = 0
for link in links:
edge_id += 1
link["id"] = edge_id
links_id.append(link)
B["edges"] = []
B["edges"] = links_id
if field1 == field2 == 'ngrams' : if field1 == field2 == 'ngrams' :
data["nodes"] = B["nodes"] data["nodes"] = B["nodes"]
data["links"] = B["links"] data["edges"] = B["edges"]
else: else:
A = get_graphA( "journal" , nodesB_dict , B["links"] , corpus ) A = get_graphA( "journal" , nodesB_dict , B["edges"] , corpus )
print("#nodesA:",len(A["nodes"])) print("#nodesA:",len(A["nodes"]))
print("#linksAA + #linksAB:",len(A["links"])) print("#linksAA + #linksAB:",len(A["links"]))
print("#nodesB:",len(B["nodes"])) print("#nodesB:",len(B["nodes"]))
print("#linksBB:",len(B["links"])) print("#linksBB:",len(B["links"]))
data["nodes"] = A["nodes"] + B["nodes"] data["nodes"] = A["nodes"] + B["nodes"]
data["links"] = A["links"] + B["links"] data["edges"] = A["edges"] + B["edges"]
print(" total nodes :",len(data["nodes"])) print(" total nodes :",len(data["nodes"]))
print(" total links :",len(data["links"])) print(" total links :",len(data["edges"]))
print("") print("")
elif type == "adjacency": elif type == "adjacency":
......
...@@ -13,32 +13,33 @@ def compress_graph(graphdata): ...@@ -13,32 +13,33 @@ def compress_graph(graphdata):
"nodes": [{"id":4103, "at":{"cl": 0}, "s":29, "lb":"regard"},...] "nodes": [{"id":4103, "at":{"cl": 0}, "s":29, "lb":"regard"},...]
"links": [{"t": 998,"s": 768,"w": 0.042},...] "links": [{"t": 998,"s": 768,"w": 0.042},...]
""" """
for link in graphdata['links']:
link['w'] = format(link['w'], '.3f') # keep only 3 decimals
for node in graphdata['nodes']:
node['lb'] = node['label']
del node['label']
#node['attributes']['growth'] = 0.8
node['at'] = node['attributes']
del node['attributes']
node['at']['cl'] = node['at']['clust_default']
del node['at']['clust_default']
node['s'] = node['size']
del node['size']
if node['type'] == "terms":
# its the default type for our format: so we don't need it
del node['type']
else:
node['t'] = node['type']
del node['type']
return graphdata return graphdata
# for link in graphdata['links']:
# link['w'] = format(link['w'], '.3f') # keep only 3 decimals
#
# for node in graphdata['nodes']:
# node['lb'] = node['label']
# del node['label']
#
# #node['attributes']['growth'] = 0.8
#
# node['at'] = node['attributes']
# del node['attributes']
#
# node['at']['cl'] = node['at']['clust_default']
# del node['at']['clust_default']
#
# node['s'] = node['size']
# del node['size']
#
# if node['type'] == "terms":
# # its the default type for our format: so we don't need it
# del node['type']
# else:
# node['t'] = node['type']
# del node['type']
#
# return graphdata
def format_html(link): def format_html(link):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment