abc123 / hack /test_wordnet_simple.py
vimalk78's picture
feat(crossword): generated crosswords with clues
486eff6
raw
history blame
3.43 kB
#!/usr/bin/env python3
"""
Simple test for WordNet clue generator functionality.
Tests basic clue generation without heavy initialization.
"""
import sys
from pathlib import Path
# Add hack directory to path
sys.path.insert(0, str(Path(__file__).parent))
def test_basic_wordnet():
"""Test basic WordNet functionality."""
print("πŸ§ͺ Basic WordNet Test")
print("=" * 30)
try:
import nltk
from nltk.corpus import wordnet as wn
print("βœ… NLTK and WordNet imported")
# Test basic synset lookup
test_words = ['cat', 'computer', 'run']
for word in test_words:
synsets = wn.synsets(word)
print(f"\nπŸ“ '{word}': {len(synsets)} synsets")
if synsets:
# Show first synset info
first = synsets[0]
print(f" Definition: {first.definition()}")
print(f" Examples: {first.examples()[:1]}")
# Show synonyms
synonyms = [lemma.name().replace('_', ' ') for lemma in first.lemmas()[:3]]
print(f" Synonyms: {synonyms}")
# Show hypernyms (categories)
hypernyms = [hyp.lemmas()[0].name().replace('_', ' ') for hyp in first.hypernyms()[:2]]
print(f" Categories: {hypernyms}")
return True
except Exception as e:
print(f"❌ Error: {e}")
return False
def test_clue_generation_simple():
"""Test simple clue generation logic."""
print("\n🎯 Simple Clue Generation Test")
print("=" * 35)
try:
from nltk.corpus import wordnet as wn
test_words = ["dog", "computer", "guitar"]
for word in test_words:
synsets = wn.synsets(word)
if synsets:
# Test definition-based clue
definition = synsets[0].definition()
print(f"\n{word.upper()}: {definition}")
# Simple clue processing - avoid target word in definition
clue = definition.lower()
if word.lower() not in clue:
clue = clue.capitalize()
if len(clue) > 50:
clue = clue[:47] + "..."
print(f"Generated clue: {clue}")
else:
print(f"Skipped (contains target word)")
return True
except Exception as e:
print(f"❌ Clue generation error: {e}")
return False
def main():
"""Run simple tests."""
print("πŸš€ WordNet Simple Test Suite")
print("=" * 40)
# Test basic functionality
basic_ok = test_basic_wordnet()
if basic_ok:
# Test clue generation
clue_ok = test_clue_generation_simple()
if clue_ok:
print("\nβœ… Basic WordNet functionality working!")
print("πŸ’‘ Ready to test full WordNet clue generator")
else:
print("\n⚠️ Basic WordNet works, but clue generation needs work")
else:
print("\n❌ WordNet not working properly")
print("πŸ’‘ Try: pip install nltk, then python -c 'import nltk; nltk.download(\"wordnet\")'")
return basic_ok and clue_ok
if __name__ == "__main__":
main()