Skip to content

Commit

Permalink
Create sentiment_analysis.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 26, 2024
1 parent 04616ca commit b0d0276
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions QuantumNexusProtocol/src/ai/sentiment_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pandas as pd
from textblob import TextBlob

class SentimentAnalyzer:
def __init__(self, data):
self.data = data

def analyze_sentiment(self):
self.data['sentiment'] = self.data['text'].apply(lambda x: TextBlob(x).sentiment.polarity)
return self.data[['text', 'sentiment']]

# Example usage
if __name__ == "__main__":
data = pd.DataFrame({'text': ['I love this!', 'This is terrible.', 'I am neutral.']})
analyzer = SentimentAnalyzer(data)
results = analyzer.analyze_sentiment()
print("Sentiment Analysis Results:\n", results)

0 comments on commit b0d0276

Please sign in to comment.