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() |