|
|
|
|
|
""" |
|
|
Quick test to verify K-Means returns proper format |
|
|
""" |
|
|
import sys |
|
|
sys.path.insert(0, '/home/deepu/Downloads/code2') |
|
|
|
|
|
from risk_discovery import UnsupervisedRiskDiscovery |
|
|
|
|
|
|
|
|
sample_clauses = [ |
|
|
"The Company shall not be liable for any indirect damages.", |
|
|
"Either party may terminate this Agreement upon 30 days notice.", |
|
|
"All intellectual property rights remain with the Company.", |
|
|
"Customer agrees to pay monthly fees of $10,000.", |
|
|
"Each party shall keep confidential all information disclosed.", |
|
|
"The Service Provider agrees to indemnify the Client.", |
|
|
"This Agreement shall automatically terminate upon bankruptcy.", |
|
|
"Vendor shall maintain compliance with ISO 27001 standards.", |
|
|
] |
|
|
|
|
|
print("="*80) |
|
|
print("Testing K-Means Risk Discovery Return Format") |
|
|
print("="*80) |
|
|
|
|
|
|
|
|
discovery = UnsupervisedRiskDiscovery(n_clusters=3, random_state=42) |
|
|
results = discovery.discover_risk_patterns(sample_clauses) |
|
|
|
|
|
|
|
|
print("\n" + "="*80) |
|
|
print("Checking Result Structure") |
|
|
print("="*80) |
|
|
|
|
|
required_keys = ['method', 'n_clusters', 'discovered_patterns', 'cluster_labels', 'quality_metrics'] |
|
|
for key in required_keys: |
|
|
if key in results: |
|
|
print(f"β
'{key}' present") |
|
|
if key == 'method': |
|
|
print(f" Value: {results[key]}") |
|
|
elif key == 'n_clusters': |
|
|
print(f" Value: {results[key]}") |
|
|
elif key == 'quality_metrics': |
|
|
print(f" Metrics: {list(results[key].keys())}") |
|
|
else: |
|
|
print(f"β '{key}' MISSING") |
|
|
|
|
|
print("\n" + "="*80) |
|
|
print("Discovered Patterns:") |
|
|
print("="*80) |
|
|
for pattern_name, details in results['discovered_patterns'].items(): |
|
|
print(f"\n{pattern_name}:") |
|
|
print(f" Clauses: {details['clause_count']}") |
|
|
print(f" Key terms: {', '.join(details['key_terms'][:5])}") |
|
|
|
|
|
print("\n" + "="*80) |
|
|
if all(key in results for key in required_keys): |
|
|
print("β
TEST PASSED: All required keys present") |
|
|
else: |
|
|
print("β TEST FAILED: Missing required keys") |
|
|
print("="*80) |
|
|
|