File size: 2,833 Bytes
a01e687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Quick tests for the analysis tools."""

import sys
import os

# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))

from tools import WordCounter, KeywordExtractor, SentimentAnalyzer


def test_word_counter():
    """Test word counter tool."""
    print("Testing Word Counter...")
    tool = WordCounter()

    test_text = "This is a test. This is only a test. Testing is important."
    result = tool.run(test_text)

    print(f"  Total words: {result['total_words']}")
    print(f"  Unique words: {result['unique_words']}")
    print(f"  Top words: {result['top_10_words'][:3]}")
    print("  ✓ Word Counter works!\n")


def test_keyword_extractor():
    """Test keyword extractor tool."""
    print("Testing Keyword Extractor...")
    tool = KeywordExtractor()

    test_text = """
    Machine learning is a subset of artificial intelligence.
    Deep learning algorithms use neural networks to process data.
    Natural language processing helps computers understand human language.
    """
    result = tool.run(test_text)

    print(f"  Keywords found: {result['num_keywords']}")
    print(f"  Top 3 keywords:")
    for kw in result['keywords'][:3]:
        print(f"    - {kw['word']}: {kw['score']}")
    print("  ✓ Keyword Extractor works!\n")


def test_sentiment_analyzer():
    """Test sentiment analyzer tool."""
    print("Testing Sentiment Analyzer...")
    tool = SentimentAnalyzer()

    # Positive text
    positive_text = "This is wonderful! I love it. Great experience, highly recommended!"
    result = tool.run(positive_text)
    print(f"  Positive text sentiment: {result['sentiment_label']} ({result['sentiment_score']})")

    # Negative text
    negative_text = "This is terrible. I hate it. Awful experience, very disappointed."
    result = tool.run(negative_text)
    print(f"  Negative text sentiment: {result['sentiment_label']} ({result['sentiment_score']})")

    # Neutral text
    neutral_text = "The product arrived on Tuesday. It has a blue color."
    result = tool.run(neutral_text)
    print(f"  Neutral text sentiment: {result['sentiment_label']} ({result['sentiment_score']})")

    print("  ✓ Sentiment Analyzer works!\n")


if __name__ == "__main__":
    print("=" * 60)
    print("ReAct Text Analyzer - Tool Tests")
    print("=" * 60 + "\n")

    try:
        test_word_counter()
        test_keyword_extractor()
        test_sentiment_analyzer()

        print("=" * 60)
        print("✅ All tests passed!")
        print("=" * 60)
        print("\nYou can now run the Streamlit app:")
        print("  cd src && streamlit run app.py")
        print("\nOr use the quick start script:")
        print("  ./run.sh")

    except Exception as e:
        print(f"\n❌ Test failed: {e}")
        import traceback
        traceback.print_exc()