-
Notifications
You must be signed in to change notification settings - Fork 1
/
arabic_boundary_score_calculation.py
32 lines (29 loc) · 1.15 KB
/
arabic_boundary_score_calculation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from igraph import *
import pandas as pd
g = load("boundary_labeled_graphs/arabic_boundary_edges.graphml")
vs = g.vs.select(topic_eq = "None")
sum_node_values = 0
sum_boundary_nodes = 0
for topic in vs:
boundary_vs = g.vs.select(status_eq = "boundary" + topic["name"]) #get topic's boundary nodes
internal_vs = g.vs.select(status_eq = "internal" + topic["name"])
total_vs = g.vs.select(topic_eq = topic["name"])
print(topic["name"] + ": ")
print(len(internal_vs) / len(total_vs) )
sum_boundary_nodes+=len(boundary_vs)
node_value = 0
for boundary_node in boundary_vs: #for each boundary node in this topic, 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
node_value += (internalSum / (internalSum + boundarySum)) - 0.5
sum_node_values += node_value
print(sum_node_values)
print(sum_boundary_nodes)
print(sum_node_values / sum_boundary_nodes)