File size: 2,509 Bytes
3d4ed4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Legacy benchmark module retained only for historical comparison.

Production HeedX functionality uses the qualitative analysis engine,
conversation state manager, safety layer, and RAG engine instead of the
old classification-based assessment pipeline.
"""

# Intentionally left in place for compatibility with older scripts and
# research benchmarking, but it is no longer used in the active app flow.

import pandas as pd
import numpy as np
from collections import Counter
import re
from .preprocessing import preprocess_text, split_sentences
from .lexicons import (
    INTENSITY_KEYWORDS, RESILIENCE_KEYWORDS, CRISIS_TRIGGERS,
    NEGATIONS, WELLNESS_KEYWORDS
)
from config.settings import RISK_THRESHOLDS


class MentalHealthAnalyzer:
    """Deprecated legacy analyzer. Not used by the active migratable app."""

    def __init__(self, model, classes):
        self.model = model
        self.classes = classes
        self.sentence_predictions = []
        self.aggregated_results = {}
        self.intensity_keywords = INTENSITY_KEYWORDS
        self.resilience_keywords = RESILIENCE_KEYWORDS
        self.crisis_triggers = CRISIS_TRIGGERS
        self.negations = NEGATIONS
        self.wellness_keywords = WELLNESS_KEYWORDS
        self.classes_list = list(self.classes)
        self.thresholds = RISK_THRESHOLDS

    def _is_target_negated(self, target_pattern, text, window=3):
        return False

    def _detect_negated_wellness(self, text, window=3):
        return False

    def _detect_negated_distress(self, text, window=3):
        return False

    def _evaluate_crisis_intent(self, cleaned_text):
        return False, False, False

    def _calculate_intensity(self, sentence):
        return 1.0

    def _detect_resilience(self, sentence):
        return False

    def analyze_response(self, text, question_id=None):
        return []

    def analyze_all_responses(self, responses_dict):
        return []

    def _extract_markers(self, sentence, actual_crisis_intent=False, is_crisis_negated=False, is_negated_wellness=False):
        return []

    def _aggregate_predictions(self):
        return {}

    def get_risk_level(self):
        return "unknown"

    def get_suicidal_flagged_sentences(self):
        return []


def create_distribution_dataframe(distribution):
    df = pd.DataFrame({
        'Mental Health Indicator': list(distribution.keys()),
        'Percentage': list(distribution.values())
    })
    return df.sort_values('Percentage', ascending=False)