-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_pull.py
276 lines (197 loc) · 6.26 KB
/
analyze_pull.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
from mpl_toolkits import mplot3d
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
class Vertex():
loc = []
id = 0
name = ''
date = ''
links = []
vid = 0
def link(self, vertex):
self.links.append(vertex)
def create(self, x, y, z):
self.loc = [x, y, z]
class Xet():
loc = []
layers = []
name = ''
verteces = []
children = []
flag = False
def append(self, vertex):
self.children.append(vertex)
def id_tree(self):
ch = self.children
ids = list()
for child in ch:
ids.append(child.id)
return ids
def vertex_tree(self):
ch = self.verteces
names = list()
for child in ch:
names.append(child.id)
return names
def intersect(self, xet):
t1 = self.id_tree()
t2 = xet.id_tree()
inter_list = list()
for t in t1:
if (t in t2):
inter_list.append(t)
return inter_list
def intersect_vn(self, xet):
t1 = self.vertex_tree()
t2 = xet.vertex_tree()
inter_list = list()
for t in t1:
if (t in t2):
inter_list.append(t)
return inter_list
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def assemble_verteces(csv_directory):
overall_df = pd.read_csv(filepath_or_buffer=csv_directory)
id_count = 0
vertex_list = list()
for c in range(len(overall_df.iloc[:]['id'])):
v = Vertex()
v.id = overall_df.iloc[c]['id']
v.name = overall_df.iloc[c]['name']
v.date = overall_df.iloc[c]['date']
v.vid = id_count
#v.links = filter_id(overall_df, id)
v.create(v.id, overall_df.iloc[c]['parent'], overall_df.iloc[c]['layer'])
# trim v.name
if not (v.name.find(',') + 3 >= len(v.name)):
v.name = v.name[:v.name.find(',') + 3]
vertex_list.append(v)
id_count += 1
return vertex_list
def filter_id(df, id):
id_count = 0
ids_list = list()
found = False
for c in range(len(df.iloc[:]['id'])):
if df.iloc[c]['id'] == id:
ids_list.append(id_count)
found = True
elif found:
break
id_count += 1
return ids_list
def get_unique_citations(vector_list):
unique_id_list = list()
for v in vector_list:
if not (len(unique_id_list) == 0) and not (unique_id_list[-1] == v.id) and not (v.id in unique_id_list):
unique_id_list.append(v.id)
return unique_id_list
def get_parent_list(vertex_list):
all_parents = list()
for v in vertex_list:
p = v.loc[1]
if not p in all_parents:
all_parents.append(p)
return all_parents
def transform_verteces_into_xet(vertex_list):
xet_list = list()
xet_names = list()
for v in vertex_list:
if not v.name in xet_names:
x = Xet()
x.name = v.name
x.layers = [v.loc[1]]
x.loc = [v.id, v.loc[1], v.loc[2]]
x.verteces.append(v)
xet_names.append(v.name)
xet_list.append(x)
else:
index = xet_names.index(v.name)
xet = xet_list[index]
xet.verteces.append(v)
xet.layers.append(v.loc[1])
xet.flag = True
xet_list[index] = xet
return xet_list
def hloc(xyz, value, vertex_list):
count = 0
for v in vertex_list:
if v.loc[xyz] == value:
return count
else:
count += 1
return -1
def dloc_name(name, data_list):
count = 0
for d in data_list:
if d.name == name:
return count
else:
count += 1
return -1
def hfilter_flag(xet_list, find_flag=True):
xet_list_flag = list()
for x in xet_list:
if x.flag == find_flag:
xet_list_flag.append(x)
return xet_list_flag
def hfilter(xyz, value, xet_list):
xet_list_flag = list()
for x in xet_list:
if x.loc[xyz] == value:
xet_list_flag.append(x)
return xet_list_flag
def print_xet_list(xet_list):
count = 0
for x in xet_list:
print("{0:7} name: {1:20} id: {2:10} num_children: {3:5} num_verteces: {4:8}".format(count, x.name, x.loc[0], len(x.children), len(x.verteces)) )
count += 1
def print_xet(xet):
print(xet.name)
for v in xet.verteces:
print_vertex(v)
def print_vertex(v):
print(v.name)
for v2 in v.links:
print_vertex(v2)
def find_repeats(q_list):
count_list = list()
ret_list = list()
for q in q_list:
if q in count_list:
ret_list.append(q)
else:
count_list.append(q)
return ret_list
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vertex_list = assemble_verteces("/Users/mkorovkin/Desktop/citations_2015_data_ms450469.csv")
unique_citations = get_unique_citations(vertex_list)
parent_citation = get_parent_list(vertex_list)
xet_list = transform_verteces_into_xet(vertex_list)
print("vertex list: " + str(len(vertex_list)))
print("xet list: " + str(len(xet_list)))
xxxx = dloc_name('lucae, s', vertex_list)
print(xxxx)
print("lucae, susanne: " + str(dloc_name('lucae, s', vertex_list[(xxxx + 1):])))
for x in xet_list:
count = 0
if x.name == 'lucae, s':
print("location {0:15} name: {1:20} id: {2:10} num_children: {3:15} vertex_length {4:8}".format(count, x.name, x.loc[0], len(x.children), len(x.verteces)))
break
count += 1
for parent_id in parent_citation:
L = hfilter(1, parent_id, xet_list)
print(len(L))
print(L)
Q = list()
for x in L:
Q.append(x.name)
print(len(find_repeats(Q)))
flagged_list = hfilter_flag(xet_list)
print_xet_list(flagged_list)
#print(len(flagged_list[0].verteces))
#print(len(flagged_list[1].verteces))
#print(len(flagged_list[0].intersect_vn(flagged_list[1])))
# Cross reference Xet authors with one another and locate them in the vertex list
# lucae, susanne appears like 3 or 4 times in the data but does not show up as a repeat