import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
# Initialize the sentiment analyzer
sia = SentimentIntensityAnalyzer()
# Text dataset for sentiment analysis
dataset = [
"I love this product! It's amazing.",
"The service was terrible. I'm very disappointed.",
"The movie was okay, but the ending was disappointing.",
"I had a great experience with their customer support.",
"The book is fantastic! Highly recommended."
]
# Perform sentiment analysis on each text in the dataset
for text in dataset:
sentiment = sia.polarity_scores(text)
compound_score = sentiment['compound']
if compound_score >= 0.5:
print(f"Positive sentiment: {text}")
elif compound_score <= -0.5:
print(f"Negative sentiment: {text}")
else:
print(f"Neutral sentiment: {text}")