Skip to content

Commit

Permalink
added users boundary code
Browse files Browse the repository at this point in the history
  • Loading branch information
yasmeenhany committed Jun 7, 2019
1 parent 6268d5f commit 1998e68
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arabic_boundary_score_calculation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from igraph import *
import pandas as pd
g = load("boundary_labeled_graphs/arabic_boundary_edges.graphmll")
g = load("boundary_labeled_graphs/arabic_boundary_edges.graphml")
vs = g.vs.select(topic_eq = "None")
sum_node_values = 0
sum_boundary_nodes = 0
Expand Down
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase1_users_boundary_edges.graphml
Git LFS file not shown
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase1_users_boundary_nodes.graphml
Git LFS file not shown
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase2_users_boundary_edges.graphml
Git LFS file not shown
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase2_users_boundary_nodes.graphml
Git LFS file not shown
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase3_users_boundary_edges.graphml
Git LFS file not shown
3 changes: 3 additions & 0 deletions boundary_labeled_graphs/phase3_users_boundary_nodes.graphml
Git LFS file not shown
33 changes: 33 additions & 0 deletions users_boundary_score_calculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from igraph import *
import pandas as pd
g = load("boundary_labeled_graphs/phase1_users_boundary_edges.graphml")
# g = load("boundary_labeled_graphs/phase2_users_boundary_edges.graphml")
# g = load("boundary_labeled_graphs/phase3_users_boundary_edges.graphml")
vs = g.vs.select(polar_eq = "None")
sum_node_values = 0
sum_boundary_nodes = 0
for polar in vs:
boundary_vs = g.vs.select(status_eq = "boundary" + polar["name"]) #get polar's boundary nodes
sum_boundary_nodes+=len(boundary_vs)
node_value = 0
for boundary_node in boundary_vs: #for each boundary node in this polar, calculate di and db
incident_edges = g.incident(boundary_node)
boundarySum = 0
internalSum = 0
for edge in incident_edges:
full_edge = g.es.select(edge)[0]
if(full_edge["status"][0:9] == "Eboundary"):
boundarySum +=1
else:
internalSum +=1
if (internalSum + boundarySum != 0):
node_value += (internalSum / (internalSum + boundarySum)) - 0.5
else:
node_value = 0
sum_node_values += node_value
print(sum_node_values)
print(sum_boundary_nodes)
print(sum_node_values / sum_boundary_nodes)



25 changes: 25 additions & 0 deletions users_labeling_boundary_edges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from igraph import *
import pandas as pd
g = load("boundary_labeled_graphs/phase1_users_boundary_nodes.graphml")
# g = load("boundary_labeled_graphs/phase2_users_boundary_nodes.graphml")
# g = load("boundary_labeled_graphs/phase3_users_boundary_nodes.graphml")
vs = g.vs.select(polar_eq = "None")
for polar in vs:
boundary_vs = g.vs.select(status_eq = "boundary" + polar["name"]) #get boundary vertices of each polar
for boundary_node in boundary_vs:
incident_edges = g.incident(boundary_node)
for edge in incident_edges:
full_edge = g.es.select(edge)[0]
if(full_edge.source == boundary_node.index): #means boundary node is src
opp_node = g.vs.select(full_edge.target)[0]
if(full_edge.target == boundary_node.index): #means boundary node is target
opp_node = g.vs.select(full_edge.source)[0]
my_boundary = "boundary" + polar["name"] #name of my community's boundary nodes
if(opp_node["status"][0:8] == "boundary" and opp_node["status"]!= my_boundary and opp_node["polar"] != 'None' and boundary_node["polar"] != 'None'): #if boundary node from diff community
g.es[edge]["status"] = "Eboundary" + polar["name"]
elif(opp_node["status"] == "internal"+ polar["name"]): #if internal node from my community
g.es[edge]["status"] = "Einternal" + polar["name"]

g.save("boundary_labeled_graphs/phase1_users_boundary_edges.graphml")
# g.save("boundary_labeled_graphs/phase2_users_boundary_edges.graphml")
# g.save("boundary_labeled_graphs/phase3_users_boundary_edges.graphml")
26 changes: 26 additions & 0 deletions users_labeling_boundary_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from igraph import *
import pandas as pd
g = load("users_graphs/p1_users_graph_with_polar.graphml")
# g = load("users_graphs/p2_users_graph_with_polar.graphml")
# g = load("users_graphs/p3_users_graph_with_polar.graphml")
vs = g.vs.select(polar_eq = "None")
g.vs["status"] = None
print(len(vs))
for pole in vs: #for each community Gi
if (pole != "neu"):
# print(topic)
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"]): #normal node from other pole/reply
member["status"] = "boundary"+ member["polar"]
for v in g.vs:
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/phase1_users_boundary_nodes.graphml")
# g.save("boundary_labeled_graphs/phase2_users_boundary_nodes.graphml"
# g.save("boundary_labeled_graphs/phase3_users_boundary_nodes.graphml"

0 comments on commit 1998e68

Please sign in to comment.