-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNN_1.py
106 lines (90 loc) · 2.56 KB
/
GNN_1.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
import numpy as np
weights = []
# Creating the Laplacian matrix interpretation of our graph
Laplacian = np.matrix([[1, -1, 0, 0, 0, 0], [-1, 2, -1, 0, 0, 0],
[0, -1, 4, -1, -1, -1], [0, 0, -1, 2, -1, 0], [0, 0, -1, -1, 2, 0],
[0, 0, -1, 0, 0, 1]], np.int32)
# Creating the feature vector
Features = np.array([1, 7, 3, 4, 2, 1])
# Are both arrays read into our code
#print(Features.shape)
#print(Laplacian.shape)
# Reading in the contents of our Manuscript transliteration
with open('Manuscript.txt', encoding='utf8') as f:
lines = f.read()
charmap = []
manuscript = []
flag = 0
#getting characters from transliteration and cleaning the indices from the manuscript
for x in lines:
if x == '<':
flag = 1
if flag == 0:
manuscript.append(x)
if x in charmap:
continue
else:
charmap.append(x)
if x == '>':
if flag == 1:
flag = 0
#print(charmap)
features = {}
count = np.zeros((len(charmap), ))
z=0
#getting our feature vector, representing how many times each character is used in the text
for x in charmap:
n = 0
for y in manuscript:
if y == x:
n=n+1
#print(str(x) + " " + str(n))
count[z]=n
z+=1
features.update({x: n})
print(features)
print(count)
Laplace2 = np.zeros((len(charmap), len(charmap)))
#print(Laplace2)
n = -1
#getting our Laplacian representation of the graph, where the characters are nodes and their neighbors are edges
for x in charmap:
manuindex = -1
n += 1
Laplace2[n,n] = count[n]
for y in manuscript:
manuindex+=1
if y == x:
index = -1
for z in charmap:
index+=1
if manuscript[manuindex-1] == z:
Laplace2[n, index]-=1
if(manuindex+1<len(manuscript)):
if manuscript[manuindex+1] == z:
Laplace2[n, index]-=1
#print(x)
#print(charmap[n])
print(Laplace2)
print(sorted(features.items(), key=lambda kv:
(kv[1], kv[0])))
print(33756/sum(features.values()))
print(25055/sum(features.values()))
print(17439/sum(features.values()))
print(14497/sum(features.values()))
print(13751/sum(features.values()))
n = -1
for x in charmap:
n+=1
if x=='.':
break
print(charmap[n])
track = 0
i = 0
for num in range(len(charmap)):
if(Laplace2[n, num])<track:
track=Laplace2[n, num]
i = num
print(Laplace2[n, num])
print("most commonly occuring char nearby: " + str(charmap[i]))
print("edges: " + str(track))