-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_file.py
79 lines (71 loc) · 2.19 KB
/
main_file.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
import os
import GetXML
import inverted_idx
inverted_index = {}
def searchen(lemma):
final={}
for i in lemma:
if i in inverted_index:
found = inverted_index[i]
for j in found:
if j in final:
final[j]+=found[j]
else:
final[j]=found[j]
sor = sorted(final.items(), key=lambda x: x[1], reverse = True)
return sor
print("GLOSSIKI TEXNOLOGIA")
print("Enter 1 to extract text and create vertices,\n2 to create inverted index,\n3 to load inverted index\nor 0 to exit: ")
select = int(raw_input())
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
while select != 0:
if select == 1:
dir_list = [x for x in os.walk(".", topdown=True)]
for directory in dir_list[0][1]:
if directory != "vertices" and directory != "crawls":
print("Creating vertices for: "+directory)
os.system("cd "+directory+" && python *scrapy.py && python tokenizer.py")
elif select == 2:
inverted_idx.main(inverted_index)
lemma_list = []
count = 1
while True:
print("Enter search query terms (type \'exit!\' to finish query or exit search)")
print("Term "+ str(count) + ": ")
term = str(raw_input())
if term == "exit!":
break
while term != "exit!":
count = count + 1
lemma_list.append(term)
print("Term "+ str(count) + ": ")
term = str(raw_input())
if lemma_list:
results = searchen(lemma_list)
for i in results:
print i
elif select == 3:
print("Enter filename of inverted index to be loaded (.xml format): ")
file = str(raw_input())
inverted_index = GetXML.GetXML(file)
lemma_list = []
count = 1
while True:
print("Enter search query terms (type \'exit!\' to finish query or exit search)")
print("Term "+ str(count) + ": ")
term = str(raw_input())
if term == "exit!":
break
while term != "exit!":
count = count + 1
lemma_list.append(term)
print("Term "+ str(count) + ": ")
term = str(raw_input())
if lemma_list:
results = searchen(lemma_list)
for i in results:
print i
print("Enter 1 to extract text and create vertices,\n2 to create inverted index,\n3 to load inverted index\nor 0 to exit: ")
select = int(raw_input())
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
print("Done!")