File size: 3,296 Bytes
d53b325
 
 
 
 
 
 
 
 
 
 
 
2279511
d53b325
2279511
d53b325
 
 
2279511
 
 
 
 
 
 
 
d53b325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from smolagents.tools import Tool
import json
import pronouncing

class ParodyWordSuggestionTool(Tool):
    name = "parody_word_suggester"
    description = """Suggests phonetically similar funny words using CMU dictionary pronunciations.

    Returns similar words from a curated list of funny words, along with their similarity scores."""
    inputs = {'target': {'type': 'string', 'description': 'The word you want to find funny alternatives for'}, 'min_similarity': {'type': 'string', 'description': 'Minimum similarity threshold (0.0-1.0)', 'nullable': True}}
    output_type = "string"

    def __init__(self):
        # Initialize with funny word list
        self.funny_words = [
            # Original words
            "poop", "loop", "soup", "boop", "dupe", "goop",
            "scoop", "whoop", "droop", "snoop", "coop",
            "fart", "toot", "burp", "squish", "squash",
            "wiggle", "jiggle", "wobble", "nincompoop", "dingleberry",
            # Additional middle school humor words
            "stinky", "booboo", "smelly", "goo", "turd", "pee", "peepee",
            "potty", "butt", "tooty", "booger", "snot", "doody", "doodoo",
            "weewee", "wedgie", "undies", "fartface", "poopyhead",
            "butthead", "stinkbomb", "stinkface", "dork", "nerd",
            "goober", "doofus", "dingus", "yahoo", "weirdo",
            "stinkypants", "bubblebutt", "zonked", "zoop", "zoinks"
        ]


    def forward(self, target: str, min_similarity: str = "0.7") -> str:
        """Get phonetically similar funny word suggestions."""
        import pronouncing
        import json
    
        target = target.lower().strip()
        min_similarity = float(min_similarity)
        suggestions = []
    
        # Get target pronunciation
        target_phones = pronouncing.phones_for_word(target)
        if not target_phones:
            return json.dumps({
                "error": f"'{target}' not found in CMU dictionary",
                "suggestions": []
            }, indent=2)
        
        target_phones = target_phones[0].split()
    
        # Check each funny word
        for word in self.funny_words:
            phones = pronouncing.phones_for_word(word)
            if phones:  # Only process if word is in dictionary
                phones = phones[0].split()
            
                # Calculate similarity using overlap
                overlap = len(set(phones) & set(target_phones))
                total = min(len(phones), len(target_phones))
                similarity = overlap / total if total > 0 else 0.0
            
                if similarity >= min_similarity:
                    suggestions.append({
                        "word": word,
                        "similarity": round(similarity, 3),
                        "syllables": pronouncing.syllable_count(phones)
                    })
    
        # Sort by similarity score descending
        suggestions.sort(key=lambda x: x["similarity"], reverse=True)
    
        result = {
            "target": target,
            "target_syllables": pronouncing.syllable_count(target_phones),
            "suggestions": suggestions
        }
    
        return json.dumps(result, indent=2)