messageanalyzer.sentiment_analysis ================================== .. py:module:: messageanalyzer.sentiment_analysis Functions --------- .. autoapisummary:: messageanalyzer.sentiment_analysis.analyze_sentiment Module Contents --------------- .. py:function:: analyze_sentiment(messages: List[str], model: str = 'Default') -> List[Dict[str, Union[str, float, bool]]] This function analyzes the sentiment of a list of given messages and returns the sentiment scores and labels for each messange and prints alert message if it's highly negative. :param messages: The messages to analyze. :type messages: List[str] :param model: The model to use for sentiment analysis. The "Default" model is TextBlob. :type model: str, optional :returns: A list of dictionaries, where each dictionary contains: - "messages": The original message. - "score": The sentiment polarity score. - "label": The sentiment category ("positive", "negative", "neutral"). - "alert" (optional): True if the message is highly negative. Alert will be printed if some messages are highly negative, and these messages will be displayed. :rtype: List[Dict[str, Union[str, float, bool]]] :raises TypeError: If `messages` is not a list of strings. :raises ValueError: If an unrecognized sentiment analysis model is provided. .. rubric:: Example >>> messages = ["I love this!", "This is terrible."] >>> analyze_sentiment(messages, "Default") [{'message': 'I love this!', 'score': 0.5, 'label': 'positive'}, {'message': 'This is terrible.', 'score': -1.0, 'label': 'negative', 'alert': True}]