File size: 2,530 Bytes
908ff10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Test the classification agent with sample contract clauses."""

import json
import os
from agents.classification_agent import classify_clause, classification_node

OUTPUT_DIR = os.path.join(os.path.dirname(__file__), "..", "outputs")

SAMPLE_CLAUSES = [
    {
        "id": 1,
        "text": "This Agreement shall be governed by and construed in accordance with the laws of the State of Delaware.",
        "section": "General",
    },
    {
        "id": 2,
        "text": "During the term of this Agreement and for a period of two years thereafter, the Employee shall not directly or indirectly engage in any business that competes with the Company.",
        "section": "Restrictive Covenants",
    },
    {
        "id": 3,
        "text": "Either party may terminate this Agreement at any time upon thirty (30) days prior written notice to the other party.",
        "section": "Termination",
    },
    {
        "id": 4,
        "text": "The Company shall indemnify and hold harmless the Contractor from any claims, damages, or expenses arising from the Company's breach of this Agreement.",
        "section": "Liability",
    },
    {
        "id": 5,
        "text": "The Licensor grants to the Licensee a non-exclusive, non-transferable license to use the Software solely for internal business purposes.",
        "section": "License",
    },
]


def test_single_clause():
    """Test classifying a single clause."""
    result = classify_clause(SAMPLE_CLAUSES[0]["text"])
    print(f"Clause: {SAMPLE_CLAUSES[0]['text'][:80]}...")
    print(f"Type:   {result['clause_type']}")
    print(f"Conf:   {result['confidence']}")
    print(f"Why:    {result['reasoning']}")
    print()


def test_classification_node():
    """Test the full LangGraph node with multiple clauses."""
    state = {"clauses": SAMPLE_CLAUSES}
    result = classification_node(state)

    print(f"{'ID':<4} {'Classified As':<35} {'Confidence':<12} {'Section'}")
    print("-" * 80)
    for clause in result["classified_clauses"]:
        print(f"{clause['id']:<4} {clause['clause_type']:<35} {clause['confidence']:<12.2f} {clause['section']}")

    # Save results to JSON
    output_path = os.path.join(OUTPUT_DIR, "classification_results.json")
    with open(output_path, "w") as f:
        json.dump(result["classified_clauses"], f, indent=2)
    print(f"\nResults saved to {output_path}")


if __name__ == "__main__":
    print("Single Clause Test \n")
    test_single_clause()

    print("Full Node Test \n")
    test_classification_node()