"""
NLPEnhancement
Generated by Eden via recursive self-improvement
2025-11-01 21:09:11.230902
"""

import re
from collections import defaultdict

class NLPEnhancement:
    def __init__(self):
        self.word_count = defaultdict(int)
    
    def analyze_text(self, text):
        """
        Analyzes the given text to count word frequencies.
        
        :param text: A string containing the text to be analyzed.
        :return: A dictionary with words as keys and their counts as values.
        """
        # Clean up the text
        cleaned_text = re.sub(r'\W+', ' ', text.lower())
        words = cleaned_text.split()
        
        for word in words:
            self.word_count[word] += 1
        
        return dict(self.word_count)

    def summarize_analysis(self, analysis_dict):
        """
        Summarizes and returns the top 5 most frequent words.
        
        :param analysis_dict: A dictionary of word frequencies.
        :return: A list containing the top 5 (word, frequency) pairs.
        """
        sorted_words = sorted(analysis_dict.items(), key=lambda x: x[1], reverse=True)
        return sorted_words[:5]

# Example usage
nlp_enhancement = NLPEnhancement()
text_to_analyze = "Web search results do not provide relevant information to create a new meaningful capability for Eden Autonomous Business that would help in becoming more intelligent."
analysis_result = nlp_enhancement.analyze_text(text_to_analyze)
summary = nlp_enhancement.summarize_analysis(analysis_result)

print("Word Frequencies:", analysis_result)
print("Top 5 Words:", summary)