Validation in the analysis: labels.jsonl carries review and says whether the analysis is validated (also in the sidebar list); Validate writes it there then submits; a page edit or removal is mirrored there; a resubmission keeps the ids of unchanged labels
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
effcf8fdcb
commit
ce0200a97a
3 files changed
+94
-42
No files matched your search
@@ -284,6 +284,20 @@ def label_file(station, source):
|
||||
return LABELS / source / f"{station}.jsonl"
|
||||
|
||||
|
||||
CORE = ("start", "end", "family", "description") # what a label says; the rest (id, review, analysis) is about it
|
||||
|
||||
|
||||
def core(label):
|
||||
return tuple(label.get(k) for k in CORE)
|
||||
|
||||
|
||||
def write(f, labels):
|
||||
"""Writes the labels next to the file then replaces it: an interruption does not damage it."""
|
||||
temp = f.with_name(f.name + ".tmp")
|
||||
temp.write_text("".join(json.dumps(e, ensure_ascii=False) + "\n" for e in labels), encoding="utf-8")
|
||||
os.replace(temp, f)
|
||||
|
||||
|
||||
def read(station, source):
|
||||
f = label_file(station, source)
|
||||
# split and not splitlines: the latter would also cut on the Unicode separators the text may contain
|
||||
@@ -348,5 +362,21 @@ def replace(station, source, before, label):
|
||||
temp = f.with_name(f.name + ".tmp")
|
||||
temp.write_text("\n".join(lines), encoding="utf-8")
|
||||
os.replace(temp, f)
|
||||
if before.get("analysis"):
|
||||
analysis_label(before, label)
|
||||
return label
|
||||
raise Refusal("this label is no longer in the file: reload the page")
|
||||
|
||||
|
||||
def analysis_label(before, label):
|
||||
"""A label of an analysis edited or removed in the page: the same in the labels.jsonl of the analysis, which says
|
||||
whether it is validated (its review); a resubmission then keeps the edit."""
|
||||
f = LABELS / "auto" / "analyses" / before["analysis"] / "labels.jsonl"
|
||||
if not f.exists():
|
||||
return
|
||||
labels = [json.loads(l) for l in f.read_text(encoding="utf-8").split("\n") if l.strip()]
|
||||
for i, e in enumerate(labels):
|
||||
if core(e) == core(before):
|
||||
labels[i:i + 1] = [] if label is None else [{k: label[k] for k in (*CORE, "review") if k in label}]
|
||||
write(f, labels)
|
||||
return
|
||||
Reference in new issue
Block a user