File size: 1,107 Bytes
3af75d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import json

input_path = "magpie_conversations_cemig_v0.jsonl"
output_path = "magpie_conversations_cemig_v0.jsonl"

ORDER = ["pedagogica", "aplicada", "objetiva", "instrucional"]
ALIASES = {"objetica": "objetiva"}

def norm_style(s):
    if not isinstance(s, str):
        return None
    s = s.strip().lower()
    return ALIASES.get(s, s)

def order_idx(s):
    s = norm_style(s)
    return ORDER.index(s) if s in ORDER else len(ORDER)

records = []
with open(input_path, encoding="utf-8") as f:
    for i, line in enumerate(f):
        if not line.strip():
            continue
        obj = json.loads(line)
        style = obj.get("question_style")
        cid = obj.get("context_id")
        ns = norm_style(style)
        if ns and ns != style:
            obj["question_style"] = ns
        key = (order_idx(ns), cid if isinstance(cid, int) else float("inf"), i)
        records.append((key, obj))

records.sort(key=lambda x: x[0])

with open(output_path, "w", encoding="utf-8") as out:
    for _, obj in records:
        out.write(json.dumps(obj, ensure_ascii=False) + "\n")