-
Notifications
You must be signed in to change notification settings - Fork 1
/
phase2_labeling_boundary_nodes.py
23 lines (23 loc) · 1.2 KB
/
phase2_labeling_boundary_nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from igraph import *
import pandas as pd
g = load("full_graphs_POL/phase2_polarized_full.graphml")
g.delete_vertices(g.vs.select(name_eq = "0t")[0].index) #to delete an extra node that is floating without a topic due to issue with df format
vs = g.vs.select(polar_eq = "None")
g.vs["status"] = None
print(len(vs))
for pole in vs: #for each community Gi
# if(pole["name"] != "neu"):
for member_id in g.neighbors(pole.index): #for each community member id
member = g.vs.select(member_id)[0] #get full community member
for neighbor_id in g.neighbors(member_id): # for each of neighbor'd ids
neighbor = g.vs.select(neighbor_id)[0] #get full neighbor
if (neighbor["polar"] != "None" and neighbor["polar"] != member["polar"] and member["polar"]!= "neu"): #normal node from other pole/reply
member["status"] = "boundary"+ member["polar"]
for v in g.vs:
# if (v["name"] != "neu" and v["polar"] != "neu"):
if(v["status"] is None):
if (v["polar"] == "None"): #if pole node
v["status"] = "boundary" + v["name"]
else:
v["status"] = "internal"+ v["polar"]
g.save("boundary_labeled_graphs/phase2_boundary_nodes.graphml")