|
|
|
""" |
|
Demo: WordNet-Based Crossword Generator |
|
Shows the WordNet clue generation system without full thematic integration. |
|
""" |
|
|
|
import sys |
|
from pathlib import 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 |
|
|
|
|
|
print("๐ Initializing WordNet generator...") |
|
generator = WordNetClueGenerator() |
|
|
|
if generator.initialize(): |
|
print("โ
WordNet generator ready!") |
|
else: |
|
print("โ Failed to initialize WordNet generator") |
|
return False |
|
|
|
|
|
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) |
|
|
|
|
|
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): |
|
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) |
|
|
|
|
|
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!") |
|
|
|
|
|
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() |