|
| 1 | +from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer |
| 2 | +from tkinter import * |
| 3 | + |
| 4 | +def detect_sentiment(): |
| 5 | + |
| 6 | + sentence = textArea.get("1.0", "end") |
| 7 | + sid_obj = SentimentIntensityAnalyzer() |
| 8 | + |
| 9 | + sentiment_dict = sid_obj.polarity_scores(sentence) |
| 10 | + |
| 11 | + string = str(sentiment_dict['neg']*100) + "% Negative" |
| 12 | + negativeField.insert(10, string) |
| 13 | + |
| 14 | + string = str(sentiment_dict['neu']*100) + "% Neutral" |
| 15 | + neutralField.insert(10, string) |
| 16 | + |
| 17 | + string = str(sentiment_dict['pos']*100) +"% Positive" |
| 18 | + positiveField.insert(10, string) |
| 19 | + |
| 20 | + if sentiment_dict['compound'] >= 0.05 : |
| 21 | + string = "Positive" |
| 22 | + |
| 23 | + elif sentiment_dict['compound'] <= - 0.05 : |
| 24 | + string = "Negative" |
| 25 | + else : |
| 26 | + string = "Neutral" |
| 27 | + |
| 28 | + overallField.insert(10, string) |
| 29 | + |
| 30 | +def clearAll() : |
| 31 | + |
| 32 | + negativeField.delete(0, END) |
| 33 | + neutralField.delete(0, END) |
| 34 | + positiveField.delete(0, END) |
| 35 | + overallField.delete(0, END) |
| 36 | + textArea.delete(1.0, END) |
| 37 | + |
| 38 | + |
| 39 | +gui = Tk() |
| 40 | +gui.config(background = "light blue") |
| 41 | +gui.title("Sentiment Detector") |
| 42 | + |
| 43 | +gui.geometry("500x500") |
| 44 | +enterText = Label(gui, text = "Enter Your Sentence",bg = "light blue") |
| 45 | + |
| 46 | +textArea = Text(gui, height = 10, width = 53, font = "lucida 13") |
| 47 | + |
| 48 | +check = Button(gui, text = "Check Sentiment", fg = "Black",bg = "light yellow", command = detect_sentiment) |
| 49 | +negative = Label(gui, text = "sentence was rated as: ",bg = "light blue") |
| 50 | + |
| 51 | +neutral = Label(gui, text = "sentence was rated as: ",bg = "light blue") |
| 52 | + |
| 53 | +positive = Label(gui, text = "sentence was rated as: ",bg = "light blue") |
| 54 | + |
| 55 | +overall = Label(gui, text = "Sentence Overall Rated As: ",bg = "light blue") |
| 56 | + |
| 57 | +negativeField = Entry(gui) |
| 58 | + |
| 59 | +neutralField = Entry(gui) |
| 60 | +positiveField = Entry(gui) |
| 61 | +overallField = Entry(gui) |
| 62 | +clear = Button(gui, text = "Clear", fg = "Black",bg = "light yellow", command = clearAll) |
| 63 | +Exit = Button(gui, text = "Exit", fg = "Black",bg = "light yellow", command = exit) |
| 64 | + |
| 65 | +enterText.grid(row = 0, column = 2) |
| 66 | + |
| 67 | +textArea.grid(row = 1, column = 2, padx = 10, sticky = W) |
| 68 | + |
| 69 | +check.grid(row = 2, column = 2) |
| 70 | + |
| 71 | +neutral.grid(row = 3, column = 2) |
| 72 | + |
| 73 | +neutralField.grid(row = 4, column = 2) |
| 74 | + |
| 75 | +positive.grid(row = 5, column = 2) |
| 76 | + |
| 77 | +positiveField.grid(row = 6, column = 2) |
| 78 | + |
| 79 | +negative.grid(row = 7, column = 2) |
| 80 | + |
| 81 | +negativeField.grid(row = 8, column = 2) |
| 82 | + |
| 83 | +overall.grid(row = 9, column = 2) |
| 84 | + |
| 85 | +overallField.grid(row = 10, column = 2) |
| 86 | + |
| 87 | +clear.grid(row = 11, column = 2) |
| 88 | + |
| 89 | +Exit.grid(row = 12, column = 2) |
| 90 | + |
| 91 | +gui.mainloop() |
| 92 | + |
0 commit comments