File size: 6,360 Bytes
486eff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
"""
Demo: WordNet-Based Crossword Generator
Shows the WordNet clue generation system without full thematic integration.
"""

import sys
from pathlib import Path

# Add hack directory to path
sys.path.insert(0, str(Path(__file__).parent))

def demo_wordnet_clues():
    """Demo WordNet clue generation."""
    print("๐ŸŽฏ WordNet Clue Generation Demo")
    print("=" * 50)
    
    try:
        from wordnet_clue_generator import WordNetClueGenerator
        
        # Initialize generator
        print("๐Ÿ”„ Initializing WordNet generator...")
        generator = WordNetClueGenerator()
        
        if generator.initialize():
            print("โœ… WordNet generator ready!")
        else:
            print("โŒ Failed to initialize WordNet generator")
            return False
        
        # Test word-topic combinations
        test_cases = [
            ("elephant", "animals"),
            ("piano", "music"),
            ("database", "technology"),
            ("mountain", "geography"),
            ("soccer", "sports"),
            ("pizza", "food")
        ]
        
        print(f"\n๐Ÿงช Testing {len(test_cases)} word-topic combinations")
        print("=" * 50)
        
        for word, topic in test_cases:
            print(f"\n๐Ÿ“ Word: '{word.upper()}' + Topic: '{topic}'")
            print("-" * 40)
            
            # Test different clue styles
            styles = ['definition', 'synonym', 'hypernym', 'category']
            
            for style in styles:
                try:
                    clue = generator.generate_clue(word, topic, clue_style=style)
                    status = "โœ…" if clue and len(clue) > 5 else "โŒ"
                    clue_text = clue if clue else "(no clue generated)"
                    print(f"   {status} {style:12}: {clue_text}")
                except Exception as e:
                    print(f"   โŒ {style:12}: Error - {e}")
        
        return True
        
    except Exception as e:
        print(f"โŒ Demo error: {e}")
        import traceback
        traceback.print_exc()
        return False

def demo_wordnet_info():
    """Demo WordNet information retrieval."""
    print("\n๐Ÿ“š WordNet Information Demo")
    print("=" * 50)
    
    try:
        from wordnet_clue_generator import WordNetClueGenerator
        
        generator = WordNetClueGenerator()
        if not generator.initialize():
            print("โŒ Generator not available")
            return
        
        test_words = ["elephant", "computer", "beautiful"]
        
        for word in test_words:
            print(f"\n๐Ÿ” WordNet info for: '{word}'")
            print("-" * 30)
            
            info = generator.get_clue_info(word)
            
            if 'error' in info:
                print(f"   โŒ {info['error']}")
            else:
                print(f"   Synsets found: {info['synsets_count']}")
                
                for i, synset in enumerate(info['synsets'][:2], 1):  # Show top 2
                    print(f"\n   {i}. {synset['name']} ({synset['pos']})")
                    print(f"      ๐Ÿ“– Definition: {synset['definition']}")
                    
                    if synset['synonyms']:
                        synonyms = [s for s in synset['synonyms'][:3] if s.lower() != word.lower()]
                        if synonyms:
                            print(f"      ๐Ÿ”— Synonyms: {', '.join(synonyms)}")
                    
                    if synset['hypernyms']:
                        print(f"      ๐Ÿ“‚ Categories: {', '.join(synset['hypernyms'])}")
        
    except Exception as e:
        print(f"โŒ Info demo error: {e}")

def quick_interactive_demo():
    """Quick interactive demo for testing individual words."""
    print("\n๐ŸŽฎ Quick Interactive Demo")
    print("=" * 50)
    print("Test individual words with WordNet clue generation")
    print("Enter a word, or 'quit' to exit")
    
    try:
        from wordnet_clue_generator import WordNetClueGenerator
        
        generator = WordNetClueGenerator()
        if not generator.initialize():
            print("โŒ Generator not available")
            return
        
        while True:
            user_input = input("\n๐ŸŽฏ Enter word (or 'quit'): ").strip()
            
            if user_input.lower() in ['quit', 'exit', 'q']:
                break
            
            if not user_input:
                continue
            
            word = user_input.lower()
            print(f"\n๐Ÿ“ Generating clues for: '{word.upper()}'")
            print("-" * 35)
            
            # Test all styles
            styles = ['definition', 'synonym', 'hypernym', 'category', 'descriptive']
            
            for style in styles:
                clue = generator.generate_clue(word, "", clue_style=style)
                status = "โœ…" if clue and len(clue) > 3 else "โŒ"
                clue_text = clue if clue else "(none)"
                print(f"  {status} {style:12}: {clue_text}")
    
    except KeyboardInterrupt:
        print("\n\n๐Ÿ‘‹ Exiting interactive demo")
    except Exception as e:
        print(f"โŒ Interactive demo error: {e}")

def main():
    """Run WordNet generator demos."""
    print("๐Ÿš€ WordNet Crossword Generator Demo")
    print("=" * 60)
    print("Testing NLTK WordNet-based clue generation")
    print("No API dependencies - runs completely offline!")
    
    # Run demos
    clue_demo_ok = demo_wordnet_clues()
    
    if clue_demo_ok:
        demo_wordnet_info()
        
        print("\n" + "=" * 60)
        choice = input("๐ŸŽฎ Run interactive demo? (y/n): ").strip().lower()
        if choice in ['y', 'yes']:
            quick_interactive_demo()
    
    print("\nโœ… WordNet demo complete!")
    print("\n๐Ÿ’ก This system provides:")
    print("   ๐Ÿ” Offline clue generation using WordNet definitions")
    print("   ๐Ÿ“š Multiple clue styles (definition, synonym, category, etc.)")
    print("   ๐ŸŽฏ Topic-aware clue generation")
    print("   โšก Fast generation (no API calls)")
    print("   ๐Ÿ“Š Integration ready with thematic word generator")
    
    if clue_demo_ok:
        print(f"\n๐Ÿš€ Ready for integration with thematic word discovery!")
        print(f"   Run: python wordnet_clue_generator.py")

if __name__ == "__main__":
    main()