# -*- coding: utf-8 -*-
"""Detailed test of ML model usage"""
import sys
from pathlib import Path

# Add path
sys.path.insert(0, str(Path(__file__).parent.parent / 'mcp_server' / 'analyzers'))

from lightweight_hybrid_recognizer import create_lightweight_hybrid_recognizer

print("Creating recognizer...")
recognizer = create_lightweight_hybrid_recognizer()

print("\nRecognizer statistics:")
stats = recognizer.get_statistics()
for key, value in stats.items():
    print(f"  {key}: {value}")

print("\n" + "="*60)
print("Testing some samples:")
print("="*60)

test_texts = [
    "推进一下这个事",  # workplace
    "他说来接我",  # love (ambiguous)
    "夫妻之间需要沟通",  # family
    "和同事讨论兴趣爱好",  # social
]

for text in test_texts:
    result = recognizer.recognize(text)
    print(f"\nText: {text}")
    print(f"  Scenario: {result.scenario}")
    print(f"  Confidence: {result.confidence:.3f}")
    print(f"  Method: {result.method}")

    # Check if ML was used
    if result.metadata:
        print(f"  ML used: {result.metadata.get('ml_used', False)}")
        if 'ml_error' in result.metadata:
            print(f"  ML error: {result.metadata['ml_error']}")

print("\n" + "="*60)
print("Analysis:")
print("="*60)

# Count how many use ML
ml_count = 0
rule_count = 0

for text in test_texts * 10:  # Test multiple times
    result = recognizer.recognize(text)
    if result.metadata and result.metadata.get('ml_used'):
        ml_count += 1
    else:
        rule_count += 1

print(f"ML used: {ml_count} times")
print(f"Rule engine used: {rule_count} times")
print(f"ML usage rate: {ml_count/(ml_count+rule_count)*100:.1f}%")
