|
|
|
""" |
|
Simple test for WordNet clue generator functionality. |
|
Tests basic clue generation without heavy initialization. |
|
""" |
|
|
|
import sys |
|
from pathlib import 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_words = ['cat', 'computer', 'run'] |
|
|
|
for word in test_words: |
|
synsets = wn.synsets(word) |
|
print(f"\nπ '{word}': {len(synsets)} synsets") |
|
|
|
if synsets: |
|
|
|
first = synsets[0] |
|
print(f" Definition: {first.definition()}") |
|
print(f" Examples: {first.examples()[:1]}") |
|
|
|
|
|
synonyms = [lemma.name().replace('_', ' ') for lemma in first.lemmas()[:3]] |
|
print(f" Synonyms: {synonyms}") |
|
|
|
|
|
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: |
|
|
|
definition = synsets[0].definition() |
|
print(f"\n{word.upper()}: {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) |
|
|
|
|
|
basic_ok = test_basic_wordnet() |
|
|
|
if basic_ok: |
|
|
|
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() |