[go: up one dir, main page]

0% found this document useful (0 votes)
13 views5 pages

Pythmp

The Sentiment Analysis Tool is a Python-based application that uses Tkinter for its GUI and VADER from the NLTK library to analyze text sentiment. Users can input text, and the tool will classify the sentiment as positive, negative, or neutral based on the calculated sentiment score. Future enhancements may include multilingual support and advanced NLP techniques.

Uploaded by

Sanmay Minuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Pythmp

The Sentiment Analysis Tool is a Python-based application that uses Tkinter for its GUI and VADER from the NLTK library to analyze text sentiment. Users can input text, and the tool will classify the sentiment as positive, negative, or neutral based on the calculated sentiment score. Future enhancements may include multilingual support and advanced NLP techniques.

Uploaded by

Sanmay Minuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

📚 Sentiment Analysis Tool Documentation

📝 Introduction

Sentiment analysis, also known as opinion mining, is a Natural Language


Processing (NLP) technique used to determine whether a given piece of
text expresses a positive, negative, or neutral sentiment.

This tool is built using Python's Tkinter for the graphical user interface
and VADER (Valence Aware Dictionary and Sentiment Reasoner)
from the NLTK library to analyze text sentiment. Users can enter text,
and the system will determine the sentiment score and classify it
accordingly.

Program Code

import tkinter as tk

from tkinter import scrolledtext, messagebox

import nltk

from nltk.sentiment import SentimentIntensityAnalyzer

nltk.download("vader_lexicon")

sia = SentimentIntensityAnalyzer()

def analyze_sentiment():

text = text_input.get("1.0", tk.END).strip()

if not text:

messagebox.showwarning("Warning", "Please enter some text!")

return

score = sia.polarity_scores(text)["compound"]

if score > 0.05:

sentiment = "😊 Positive"

color = "#28a745"

elif score < -0.05:


sentiment = "😠 Negative"

color = "#dc3545"

else:

sentiment = "😐 Neutral"

color = "#ffc107"

result_label.config(text=f"Sentiment: {sentiment}\nScore: {score:.3f}",


fg=color)

root = tk.Tk()

root.title("Sentiment Analysis Tool")

root.geometry("500x400")

root.configure(bg="#2C2F33")

tk.Label(root, text="Sentiment Analysis Tool", font=("Arial", 18, "bold"),


bg="#7289DA", fg="white", pady=10).pack(fill=tk.X)

tk.Label(root, text="Enter text below:", font=("Arial", 12), bg="#2C2F33",


fg="white").pack(pady=5)

text_input = scrolledtext.ScrolledText(root, height=5, width=50,


font=("Arial", 12), bg="#F0F0F0")

text_input.pack(pady=5, padx=10)

analyze_button = tk.Button(root, text="Analyze Sentiment", font=("Arial",


12, "bold"), bg="#5865F2", fg="white", padx=20, pady=5,
command=analyze_sentiment)

analyze_button.pack(pady=10)

result_label = tk.Label(root, text="", font=("Arial", 14, "bold"),


bg="#2C2F33", fg="white")

result_label.pack(pady=10)
root.mainloop()

🔍 Code Explanation

📌 Importing Required Libraries

 tkinter: Used to create the Graphical User Interface (GUI).

 scrolledtext: Provides a scrollable text box for user input.

 messagebox: Displays alerts when required (e.g., no text input).

 nltk: The Natural Language Toolkit, used for text analysis.

 SentimentIntensityAnalyzer: A VADER-based sentiment analyzer


for classifying text sentiment.

📌 Downloading the VADER Lexicon

nltk.download("vader_lexicon")

This downloads the VADER lexicon, necessary for sentiment analysis. It is


a one-time requirement per system.

📌 Initializing Sentiment Analysis

sia = SentimentIntensityAnalyzer()

This initializes the sentiment analyzer, allowing sentiment classification.

📌 Defining the Sentiment Analysis Function

def analyze_sentiment():

text = text_input.get("1.0", tk.END).strip()

if not text:

messagebox.showwarning("Warning", "Please enter some text!")

return

 Retrieves user input from the text box.

 If no text is entered, a warning message is displayed.

score = sia.polarity_scores(text)["compound"]

 This calculates the compound sentiment score (ranges from -1


to +1).

 The compound score determines the overall sentiment.


if score > 0.05:

sentiment = "😊 Positive"

color = "#28a745"

elif score < -0.05:

sentiment = "😠 Negative"

color = "#dc3545"

else:

sentiment = "😐 Neutral"

color = "#ffc107"

 Positive sentiment → score > 0.05 (green color)

 Negative sentiment → score < -0.05 (red color)

 Neutral sentiment → score between -0.05 and 0.05 (yellow color)

📚 Libraries Used

✔️Tkinter

 Python’s built-in GUI library for interactive applications.

✔️ScrolledText

 A multi-line text box with a scrollbar.

✔️Messagebox

 Used to display warnings and alerts.

✔️NLTK (Natural Language Toolkit)

 A powerful NLP library used for text analysis.

✔️VADER (Valence Aware Dictionary and Sentiment Reasoner)

 Lexicon-based sentiment analysis model, ideal for social media


and short texts.

🙌 Acknowledgment

We thank:
👉 NLTK Developers – For the NLP tools and sentiment analysis features.
👉 Python & Tkinter Community – For extensive documentation and GUI
support.
👉 VADER Authors – For creating a powerful sentiment analysis
model.

This tool is a small step toward understanding sentiment analysis.


Future enhancements may include:
🔹 Multilingual Support
🔹 Advanced NLP Techniques
🔹 Social Media Data Integration

Hope this helps! 🚀😊

You might also like