"""
SentimentAnalyzer
Generated by Eden via recursive self-improvement
2025-10-28 17:34:03.741343
"""

class SentimentAnalyzer:
    """
    A class to analyze the sentiment of a given sentence.
    
    Attributes:
        positive_words (list): List of words that indicate positive sentiment
        negative_words (list): List of words that indicate negative sentiment
        
    Methods:
        is_in_list(word, word_list): Checks if a word exists in the list
        calculate_score(word_count, total_positives, total_negatives)
            Calculates the sentiment score based on word counts
        analyze_sentiment(sentence): Analyzes and returns the sentiment
    """

    def __init__(self):
        self.positive_words = [
            "happy", "excited", "positive", "good", "great",
            "enjoy", "love", "wonderful", "awesome", "fantastic"
        ]
        
        self.negative_words = [
            "sad", "upset", "angry", "bad", "terrible",
            "hate", "dislike", "worst", "miserable", "frustrated"
        ]

    def is_in_list(self, word, word_list):
        """
        Checks if a word exists in the given list
        Returns True if found, False otherwise
        """
        return len([w for w in word_list if w == word.lower()]) > 0

    def calculate_score(self, word_count, positive_matches, negative_matches):
        """
        Calculates the sentiment score based on word counts
        Returns 'positive' or 'negative' or 'neutral'
        """
        total_positives = len(positive_matches)
        total_negatives = len(negative_matches)
        
        if total_positives > total_negatives:
            return 'positive'
        elif total_negatives > total_positives:
            return 'negative'
        else:
            return 'neutral'

    def analyze_sentiment(self, sentence):
        """
        Analyzes the sentiment of a given sentence
        Returns the overall sentiment as string: 'positive', 'negative', or 'neutral'
        """
        words = sentence.lower().split()
        positive_matches = []
        negative_matches = []

        for word in words:
            if self.is_in_list(word, self.positive_words):
                positive_matches.append(word)
            elif self.is_in_list(word, self.negative_words):
                negative_matches.append(word)

        sentiment_score = self.calculate_score(len(words), 
                                              len(positive_matches),
                                              len(negative_matches))
        
        return {
            'sentiment': sentiment_score,
            'positive_words': positive_matches,
            'negative_words': negative_matches
        }

# Example usage:
if __name__ == "__main__":
    analyzer = SentimentAnalyzer()
    test_sentence = "This is a fantastic day but the weather is terrible"
    result = analyzer.analyze_sentiment(test_sentence)
    
    print(f"Input sentence: {test_sentence}")
    print("\nSentiment Analysis:")
    print(f"Overall sentiment: {result['sentiment']}")
    print(f"Positive words found: {result['positive_words']}")
    print(f"Negative words found: {result['negative_words']}")