-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmega.py
124 lines (113 loc) · 3.16 KB
/
mega.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
def menu(): #menu function
print "===================== MENU ==========================="
print "|Press 1 \t for \t File names |"
print "| 2 \t for \t Words count in files |"
print "| 3 \t for \t Unigram search |"
print "| 4 \t for \t Bigram search |"
print "| 5 \t for \t Trigram search |"
print "| 6 \t for \t Display content |"
print "| 7 \t for \t exit |"
print "| 0 \t for \t MENU |"
print "======================================================"
menu()
i=0
while(i!=7):
choice=input("Enter ur choice >>> ")
if(choice==0):
menu()
elif(choice==1):
f=open("list.txt","r")
a=f.read()
print "Files in list.txt are >>>> \n",a
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. end of case1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==2):
f=open("list.txt","r")
a=f.read()
b=a.split()
total=0
print " File name \t\t words"
print" ============ \t ============="
for i in b:
fn=open(i,"r")
c=fn.read()
s=c.split()
print i,"\t\t",len(s)
total=total+len(s)
print "\n================================================"
print "total is : ",total
print "\n================================================"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. end of case2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==3):
se=raw_input("Enter uigram for search >> ")
f=open("list.txt","r")
a=f.read()
b=a.split()
count=0
for i in b:
fn=open(i,"r")
c=fn.read().count(se)
count+=c
print "(",se,")"," is found ",count," times"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end of case3 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==4):
f=open("list.txt","r")
a=f.read()
b=a.split()
s=0
search=raw_input("Enter a bigram for search in list.txt >>> ")
e=search.split()
for i in b:
fn=open(i,"r")
c=fn.read()
d=c.split()
count=0
for i in range(len(d)-1):
if(d[i]==e[0] and d[i+1]==e[1]):
count+=1
else:
continue
s=s+count
if(count==0):
print "NOT FOUND"
else:
print search," Is Found ",s,"times"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end of case4 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==5):
f=open("list.txt","r")
a=f.read()
b=a.split()
s=0
search=raw_input("Enter a trigram for search in list.txt >>> ")
e=search.split()
for i in b:
fn=open(i,"r")
c=fn.read()
d=c.split()
count=0
for i in range(len(d)-2):
if(d[i]==e[0] and d[i+1]==e[1] and d[i+2]==e[2]):
count+=1
else:
continue
s=s+count
if(count==0):
print "NOT FOUND"
else:
print search," Is Found ",s,"times"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end of case5 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==6):
f=open("list.txt","r")
a=f.read()
b=a.split()
for i in b:
fn=open(i,"r")
c=fn.read()
print i," >>>>>>>>> \n",c
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end of case6 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elif(choice==7):
print "Thank u....."
i=7
else:
print "INVALID OPTION..... \n"
print "Press 0 for details"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<