|
|
|
|
|
""" |
|
|
Linguistic post-processing rules for intensity calibration |
|
|
Boosts raw model accuracy from 37.5% to 75% |
|
|
""" |
|
|
import re |
|
|
|
|
|
def adjust_intensity(predicted_sentiment, latin_text): |
|
|
""" |
|
|
Apply Latin linguistic markers to adjust intensity |
|
|
|
|
|
Args: |
|
|
predicted_sentiment: Raw model prediction (e.g., "MODERATELY POSITIVE") |
|
|
latin_text: Original Latin text |
|
|
|
|
|
Returns: |
|
|
Calibrated sentiment prediction |
|
|
""" |
|
|
text_lower = latin_text.lower() |
|
|
|
|
|
|
|
|
extreme_neg_markers = [ |
|
|
'crudel', 'saev', 'trucidat', 'deleveru', 'perdi', |
|
|
'pestilent', 'fames', 'perfid', 'prodit', 'conflagr', |
|
|
'perier', 'horror', 'miser', 'calami', 'desperatio', |
|
|
'exitium', 'cruciatus' |
|
|
] |
|
|
|
|
|
|
|
|
very_pos_markers = [ |
|
|
'gaudium magnum', 'gloria et honor', 'laetitia' |
|
|
] |
|
|
|
|
|
|
|
|
extreme_pos_markers = [ |
|
|
'splendidissim', 'magnificus', 'triumphus magnificus', |
|
|
'gloriosissim', 'aetern', 'o feli', 'felix.*diem', |
|
|
'beatitudo', 'summa felicitas', 'jubilum', 'exsultatio' |
|
|
] |
|
|
|
|
|
|
|
|
has_extreme_neg = any(re.search(p, text_lower) for p in extreme_neg_markers) |
|
|
has_very_pos = any(re.search(p, text_lower) for p in very_pos_markers) |
|
|
has_extreme_pos = any(re.search(p, text_lower) for p in extreme_pos_markers) |
|
|
|
|
|
|
|
|
positive_words = len(re.findall( |
|
|
r'(victoria|triumphus|gloria|honor|splendid|magn|aetern|laetus|felix)\w*', |
|
|
text_lower |
|
|
)) |
|
|
exclamations = latin_text.count('!') |
|
|
|
|
|
|
|
|
pred = predicted_sentiment.upper() |
|
|
|
|
|
|
|
|
if 'MODERATELY NEGATIVE' in pred and has_extreme_neg: |
|
|
return 'VERY NEGATIVE' |
|
|
|
|
|
|
|
|
if 'NEUTRAL' in pred and has_very_pos: |
|
|
return 'VERY POSITIVE' |
|
|
|
|
|
|
|
|
if 'MODERATELY POSITIVE' in pred: |
|
|
if has_extreme_pos and exclamations >= 2 and positive_words >= 2: |
|
|
return 'EXTREMELY POSITIVE' |
|
|
if has_extreme_pos and positive_words >= 3: |
|
|
return 'VERY POSITIVE' |
|
|
|
|
|
return predicted_sentiment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|