from app.application.threshold_mapper import HateSpeechThresholdMapper, ThresholdConfig from app.domain.entities import ClassificationLabel, ModelScores def test_maps_hater_from_high_hate_speech_score(): mapper = HateSpeechThresholdMapper(ThresholdConfig()) result = mapper.map(ModelScores(hs=0.81, tr=0.10, ag=0.20)) assert result.predicted_label == ClassificationLabel.HATER assert result.confidence == 0.81 def test_maps_critical_from_intermediate_hate_speech_score(): mapper = HateSpeechThresholdMapper(ThresholdConfig()) result = mapper.map(ModelScores(hs=0.29, tr=0.10, ag=0.20)) assert result.predicted_label == ClassificationLabel.CRITICAL assert result.confidence == 0.29 def test_maps_neutral_when_scores_are_low(): mapper = HateSpeechThresholdMapper(ThresholdConfig()) result = mapper.map(ModelScores(hs=0.05, tr=0.10, ag=0.20)) assert result.predicted_label == ClassificationLabel.NEUTRAL assert result.confidence == 0.80 def test_text_rule_maps_direct_death_expression_as_hater_even_with_low_scores(): mapper = HateSpeechThresholdMapper(ThresholdConfig()) result = mapper.map( ModelScores( hs=0.01, tr=0.01, ag=0.01, text="Esta publicacion es horrible, asqueroso, malo totalmente, infumable, muere", ) ) assert result.predicted_label == ClassificationLabel.HATER assert result.confidence == 0.95 assert result.raw_response["rule_match"]["label"] == "hater" def test_text_rule_maps_obvious_negative_opinion_as_critical_with_low_scores(): mapper = HateSpeechThresholdMapper(ThresholdConfig()) result = mapper.map( ModelScores( hs=0.01, tr=0.01, ag=0.01, text="Esta publicacion es horrible, no me gusta para nada", ) ) assert result.predicted_label == ClassificationLabel.CRITICAL assert result.confidence == 0.85 assert result.raw_response["rule_match"]["label"] == "critico"