"""
Intelligent_Note_Organizer
Generated by Eden via recursive self-improvement
2025-10-28 05:58:09.229708
"""

class IntelligentNoteOrganizer:
    """A class to manage and organize notes intelligently by tagging and retrieving based on content.
    
    Attributes:
        notes (dict): A dictionary where each key is a note identifier, and the value is another dictionary containing 'content' and 'tags'.
        tags_index (dict): A dictionary mapping tags to list of note identifiers that contain the tag for quick search.
    """
    
    def __init__(self):
        self.notes = {}
        self.tags_index = {}
        
    def add_note(self, content, tags=None):
        """Adds a new note with optional tags. If no tags are provided, it automatically extracts keywords as tags."""
        if tags is None:
            # Simple keyword extraction (basic implementation)
            keywords = content.split()
            tags = [keyword for keyword in keywords if len(keyword) > 2]
            if not tags:
                tags = ['No Tag']
        note_id = len(self.notes) + 1
        new_note = {
            'content': content,
            'tags': tags
        }
        self.notes[note_id] = new_note
        
        # Update the tags_index
        for tag in tags:
            if tag not in self.tags_index:
                self.tags_index[tag] = []
            self.tags_index[tag].append(note_id)
        
    def search_notes(self, query):
        """Searches notes based on content or tags. Returns list of note IDs."""
        results = []
        # Search by content
        for note_id, note in self.notes.items():
            if query.lower() in note['content'].lower():
                results.append(note_id)
        # Search by tags
        if query in self.tags_index:
            results.extend(self.tags_index[query])
        return list(set(results))  # Remove duplicates
    
    def generate_summary(self):
        """Generates a summary of all notes based on frequency of tags."""
        tag_counts = {}
        for note_id, note in self.notes.items():
            for tag in note['tags']:
                if tag in tag_counts:
                    tag_counts[tag] += 1
                else:
                    tag_counts[tag] = 1
        sorted_tags = sorted(tag_counts.items(), key=lambda x: x[1], reverse=True)
        summary = "Tag Frequency Summary:\n"
        for tag, count in sorted_tags:
            summary += f"{tag}: {count} note(s)\n"
        return summary
    
    def get_note_content(self, note_id):
        """Retrieves the content of a specific note by ID."""
        if note_id in self.notes:
            return self.notes[note_id]['content']
        else:
            return "Note not found."
# Initialize the organizer
organizer = IntelligentNoteOrganizer()

# Add notes with automatic tagging
organizer.add_note("Remember to buy milk and bread tomorrow morning.", ["shopping", "reminder"])
organizer.add_note("The meeting is at 3 PM, discuss project deadlines.", ["work", "meeting"])
organizer.add_note("Python is a powerful programming language.", ["learning"])

# Search by content or tag
print(organizer.search_notes("milk"))  # Output: [1]
print(organizer.search_notes("meeting"))  # Output: [2]

# Generate summary of tags
print(organizer.generate_summary())  
# Outputs:
# Tag Frequency Summary:
# shopping: 1 note(s)
# reminder: 1 note(s)
# work: 1 note(s)
# meeting: 1 note(s)
# learning: 1 note(s)

# Retrieve specific note content
print(organizer.get_note_content(2))  
# Outputs: The meeting is at 3 PM, discuss project deadlines.