-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrontEnd.py
138 lines (102 loc) · 4.54 KB
/
FrontEnd.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
import tkinter as tk
from tkinter import *
import SentimentalAnalysis as Senti
import DataReader as db
import Statistics
import string
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
class Application():
def __init__(self):
self.Window_Create()
#self.Second_window()
def Window_Create(self):
top = tk.Tk()
top.title("Movie review")
top.geometry("500x180")
self.frame = Frame(top)
self.frame.grid()
self.label = Label(top, text="Review")
self.label.grid(row = 0 , column = 0)
self.text = Entry(top , width=55)
self.text.grid(row = 0,column = 1, columnspan = 2)
self.textbox = Text(top,width=40,height=8)
self.textbox.grid(row = 1, column=1, columnspan = 2)
self.textbox.insert(tk.END,"After Entering review press Enter:\n")
self.btn1=Button(top,text="Enter", width=20, command=self.Btn_Submit)
self.btn1.grid(row = 2 , column = 0)
self.btn2=Button(top,text="Clear", width=20, command=self.Btn_Clear)
self.btn2.grid(row = 2, column = 1)
self.btn4=Button(top,text="Submit", width=20, command=self.popupmsg)
self.btn4.grid(row = 2, column = 2)
top.mainloop()
def Btn_Submit(self):
StopWords = set(stopwords.words('english'))
dataset = db.DataReader()
sta= Statistics.Stats(dataset.unique_pos,dataset.unique_neg)
self.data = self.text.get()
words=self.data.split()
for word in words:
if word in StopWords or word in string.punctuation:
continue
else:
temp=word
print(temp)
sa = Senti.SentimentalAnalysis()
self.textbox.insert(tk.END,self.data)
self.textbox.insert(tk.END,"\nNaiveBayes Result :")
self.textbox.insert(tk.END,sa.NaiveBayes(temp,sta))
self.textbox.insert(tk.END,"\nBayesianBayes Result :")
self.textbox.insert(tk.END,sa.BayesianBayesResult(temp,sta))
def Btn_Clear(self):
self.text.delete('0',tk.END)
self.textbox.delete(1.0,tk.END)
def popupmsg(self):
NORM_FONT = ("Helvetica", 10)
self.popup = tk.Tk()
self.popup.wm_title("!")
msg="Is The Result Correct"
self.label = Label(self.popup, text=msg, font=NORM_FONT)
self.label.pack(side="top", fill="x", pady=10)
self.B1 = Button(self.popup, text="Yes", width= 20, command = self.store_data)
self.B1.pack()
self.B2 = Button(self.popup, text="No", width= 20 ,command = self.Second_window)
self.B2.pack()
self.popup.mainloop()
def store_data(self):
self.popup.destroy()
dataset = db.DataReader()
sta= Statistics.Stats(dataset.unique_pos,dataset.unique_neg)
sa = Senti.SentimentalAnalysis()
if((sa.NaiveBayes(self.data,sta) == "Positive") and (sa.BayesianBayesResult(self.data,sta) == "Positive")):
value="Pos"
if((sa.NaiveBayes(self.data,sta) == "Negative") and (sa.BayesianBayesResult(self.data,sta) == "Negative")):
value="Neg"
dataset.Store_data(value,self.data)
def Second_window(self):
window=tk.Tk()
window.title("Edit Answer")
window.geometry("400x180")
self.frame2 = Frame(window)
self.frame2.grid()
self.label2 = Label(window, text="Review")
self.label2.grid(row = 0 , column = 0)
self.text2 = Entry(window , width=55)
self.text2.grid(row = 0,column = 1, columnspan=2)
self.textbox2 = Text(window,width=40,height=8)
self.textbox2.grid(row = 1, column=1, columnspan = 2)
self.textbox2.insert(tk.END,self.data)
self.btn3=Button(window,text="Submit", width=25, command=self.update_answer)
self.btn3.grid(row = 2 , column = 1)
self.btn5=Button(window,text="Close", width=25, command=window.destroy)
self.btn5.grid(row = 2 , column = 2)
window.mainloop()
def update_answer(self):
dataset = db.DataReader()
self.data2 = self.text2.get()
if(self.data2 == "Positive" or self.data2 == "positive"):
value = "Pos"
if(self.data2 == "Negative" or self.data2 == "negative"):
value = "Neg"
dataset.Store_data(value,self.data)
app = Application()