-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThematic_Graph_Maker.py
75 lines (51 loc) · 1.65 KB
/
Thematic_Graph_Maker.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
# NIKIFORIDIS KONSTANTINOS 9084 ECE AUTH
# EXERCISE IN NETWORK THEORY
# JANUARY, 2021
import wikipedia
import networkx as nx
import random
# Theme
theme = "Tennis"
def_counter_run = 0
# english language
wikipedia.set_lang("en")
# Dimiourgia tou thematikou diktiou (directed)
themnet = nx.DiGraph()
temp_list = []
# Epipeda
level_1 = []
level_2 = []
level_3 = []
# Sinartisi pou dimiourgei komvous kai akmes analoga tin arxiki lexi
def links_nodes_edges(key_word):
global themnet
global def_counter_run
node_links = []
node_links.clear()
n = 350
try:
temp_list = wikipedia.WikipediaPage(key_word).links
for i in random.sample(temp_list, n if len(temp_list) > n else len(temp_list)):
if wikipedia.WikipediaPage(i).content.lower().count(theme.lower()) > 25 :
node_links.append(i)
themnet.add_node(i)
themnet.add_edge(key_word, i)
def_counter_run += 1
print(def_counter_run)
except:
def_counter_run += 1
print(def_counter_run)
return ["Newbie"]
return node_links #epistrefi lista me ta links-themata
level_1.append(theme)
level_2 = links_nodes_edges(theme)
print(level_2)
print("i am done with level 2")
for i in level_2:
level_3.append(links_nodes_edges(i))
print("i am done with level 3")
for i in level_3:
for j in i:
links_nodes_edges(j)
print("i am done with level 4")
nx.write_gml(themnet, "Thematic_graph_gmlformat.gml")