File size: 1,133 Bytes
7293b6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from textblob import TextBlob
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from typing import Dict, Any

def analyze_sentiment_textblob(text: str) -> TextBlob:
    """Analyze the sentiment of the given text using TextBlob.

    

    Args:

        text (str): The text to analyze.

    

    Returns:

        TextBlob: The sentiment analysis result from TextBlob.

    """
    try:
        blob = TextBlob(text)
        sentiment = blob.sentiment
        return sentiment
    except Exception as e:
        print(f"Error analyzing sentiment with TextBlob: {e}")
        return None

def analyze_sentiment_vader(text: str) -> Dict[str, Any]:
    """Analyze the sentiment of the given text using VADER.

    

    Args:

        text (str): The text to analyze.

    

    Returns:

        dict: The sentiment analysis result from VADER.

    """
    try:
        analyzer = SentimentIntensityAnalyzer()
        sentiment = analyzer.polarity_scores(text)
        return sentiment
    except Exception as e:
        print(f"Error analyzing sentiment with VADER: {e}")
        return {}