books/gu-zhenren/dc7-measure/measure_grade_render.py

21 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# $0 DC7-need measure (D39.79 Q1 / smallpack row 83-adjacent): on the labels-corpus FINALS, how many
# grade-renders deviate from the ratified canon «класс А/Б/В/Г» (甲乙丙丁等)? A deviation = a final that
# renders a grade as «разряд X» (the pre-D38.5 draft head-word) while its source carries a grade term.
import json, re
path = "/home/ubuntu/books/gu-zhenren/labels/raw/corpus.jsonl"
units = [json.loads(l) for l in open(path) if l.strip()]
grade_src = re.compile(r'[甲乙丙丁]等')
razr_grade = re.compile(r'разряд[а-я]*\s+[«"]?[АБВГ]\b') # a grade rendered as разряд (deviation)
klass_grade = re.compile(r'класс[а-я]*\s+[«"]?[АБВГ]\b') # a grade rendered as класс (canon)
dev_units = dev_occ = canon_occ = src_units = 0
for u in units:
fin, src = u.get('final','') or '', u.get('source','') or ''
if grade_src.search(src): src_units += 1
rg = razr_grade.findall(fin)
canon_occ += len(klass_grade.findall(fin))
if rg:
dev_units += 1; dev_occ += len(rg)
print(f"units={len(units)} src-has-grade-term={src_units}")
print(f"DEVIATIONS: units={dev_units} occurrences={dev_occ} (grade rendered «разряд X» ≠ canon «класс X»)")
print(f"CANON: «класс X» occurrences={canon_occ}")