-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (53 loc) · 1.92 KB
/
Copy pathmain.py
File metadata and controls
69 lines (53 loc) · 1.92 KB
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
import nltk
import tkinter
import re
import decimal
from treeGenerator import generateTree
from createDictionary import getDataset
import word
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
#add space between word and special character
def specialCharacter(sentence):
sentence = sentence.lower()
sentence = re.sub('(?<=\w)([!?,.:;/\\<>"])', r' \1', sentence)
return sentence.split()
def generateResults(input,message):
result = "Rating : "
count = 1
if(input=='' or input==None):
return
sentences = tokenizer.tokenize(input.get("1.0",'end-1c'))
for sentence in sentences:
#Split the sentence into word
wordList = nltk.pos_tag(specialCharacter(sentence),tagset='universal')
words = []
for i in wordList:
if ( i[0] in wordDataset):
words.append(word.Word(i[0],wordDataset[i[0]],i[1]))
else:
words.append(word.Word(i[0],0,"X"))
ans = generateTree(words)
if(words[-1].word=="?"):
ans = 0.00
if(ans>10):
ans = 10.00
elif(ans<-10):
ans = -10.00
result += "\nSentence {} = {}".format(count , round(ans,2) )
count += 1
message.configure(text=result)
#Get the list of words and their polarity
wordDataset = getDataset()
window =tkinter.Tk(className = 'Vichaar')
window.title("Vichaar")
window.geometry('800x500')
var = tkinter.StringVar()
label1 = tkinter.Message( window, text="Enter the sentence to be rated :",width=200,relief=tkinter.RAISED )
label1.place(x=5,y=3)
rating = tkinter.Message( window, text="Rating : ",width=200)
rating.place(x=0,y=65)
sentenceInputHolder = tkinter.Text(window,width=70,height=3)
sentenceInputHolder.place(x=200,y=2)
button = tkinter.Button(window, text ="Get Rating", command = lambda: generateResults(sentenceInputHolder,rating))
button.place(x=5,y=30)
window.mainloop()