Spaces:
Building
Building
File size: 4,171 Bytes
a543e33 dbc9105 a543e33 dbc9105 |
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 |
#!/usr/bin/env python3
"""
Extended test script to validate application functionality.
"""
import sys
import os
import tempfile
# Add the parent directory to the Python path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from text_analyzer.lexical_sophistication import LexicalSophisticationAnalyzer
from text_analyzer.pos_parser import POSParser
import pandas as pd
def test_lexical_sophistication():
"""Test lexical sophistication analysis."""
print("Testing Lexical Sophistication Analysis...")
try:
# Create analyzer
analyzer = LexicalSophisticationAnalyzer(language="en", model_size="trf")
# Test text
test_text = "The quick brown fox jumps over the lazy dog. This is a simple test sentence."
# Create dummy reference lists
with tempfile.TemporaryDirectory() as temp_dir:
# Create a dummy token file
token_file = os.path.join(temp_dir, "test_token.csv")
with open(token_file, 'w') as f:
f.write("word,score\n")
f.write("the,100\n")
f.write("quick,50\n")
f.write("brown,25\n")
f.write("fox,10\n")
f.write("jumps,5\n")
# Create a dummy lemma file
lemma_file = os.path.join(temp_dir, "test_lemma.csv")
with open(lemma_file, 'w') as f:
f.write("word,score\n")
f.write("the,100\n")
f.write("quick,50\n")
f.write("brown,25\n")
f.write("fox,10\n")
f.write("jump,5\n")
# Load reference lists
ref_lists = {
"test": {
"token": token_file,
"lemma": lemma_file
}
}
analyzer.load_reference_lists(ref_lists)
# Analyze text
results = analyzer.analyze_text(test_text, ["test"], apply_log=False)
print(f"β Processed {results['text_stats']['total_tokens']} tokens")
print(f"β Found {len(results['summary'])} summary statistics")
print(f"β Generated {len(results['token_details'])} token details")
return True
except Exception as e:
print(f"β Lexical sophistication test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_pos_parser():
"""Test POS parser functionality."""
print("\nTesting POS Parser...")
try:
# Create parser
parser = POSParser(language="en", model_size="trf")
# Test text
test_text = "The quick brown fox jumps over the lazy dog."
# Analyze text
results = parser.analyze_text(test_text)
print(f"β Processed {results['statistics']['total_tokens']} tokens")
print(f"β Found {results['statistics']['total_sentences']} sentences")
print(f"β Generated token analysis with {len(results['token_analysis'])} rows")
# Test visualization
html_outputs = parser.generate_displacy_html(test_text)
print(f"β Generated {len(html_outputs)} HTML visualizations")
return True
except Exception as e:
print(f"β POS parser test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all functionality tests."""
print("Running comprehensive application tests...")
print("=" * 60)
# Test lexical sophistication
lex_success = test_lexical_sophistication()
# Test POS parser
pos_success = test_pos_parser()
print("\n" + "=" * 60)
if lex_success and pos_success:
print("β All tests passed! Application is ready to use.")
return True
else:
print("β Some tests failed. Please check the errors above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
|