Files
cyber-tesi/scripts/gen_figures.py
T
davideandClaude Sonnet 5.5 480339b798 Allinea la wiki alla tesi aggiornata e riorganizza in hub e sottopagine
- rimappati righe, figure, tabelle e riferimenti; contenuti riscritti sui dati nuovi
- pagine spezzate per argomento (copolimeri, bottle brush, CV, fluorescenza, DPP, difetti)
- nuove pagine: p3ht, grafting-from, band-gap-homo-lumo, irreversibilita-ec, campioni,
  percorso-sintetico, glossario, tabelle-indice, figure-indice, verifica-citazioni
- schede in raw/fonti con abstract per 51 e 61; CLAUDE.md, index.md e log.md aggiornati
- riassunto-tesi non incluso

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 08:48:35 +02:00

101 lines
4.8 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.
"""Genera wiki/figures/<id>.md da raw/immagini.json. Nessun riassunto: ogni campo del catalogo viene riportato.
Uso: python scripts/gen_figures.py (rigenera tutto; le note sono derivate, non si modificano a mano)."""
import json
from pathlib import Path
root = Path(__file__).resolve().parent.parent
cat = json.loads((root / "raw/immagini.json").read_text(encoding="utf8"))
out = root / "wiki/figures"
out.mkdir(parents=True, exist_ok=True)
def q(s):
return json.dumps(str(s), ensure_ascii=False)
def lst(xs):
return "[" + ", ".join(q(x) for x in xs) + "]"
for f in cat["figures"]:
loc, qual = f["location"], f["quality"]
f["label"] = f.get("label") or f["id"] # figure senza numero stampato
v = qual.get("verification") or {}
tesi_loc = f"§{loc['section']} r.{loc['md_line']}"
fm = [
"---",
f"title: {q(' - '.join(x for x in (f['label'], f.get('title') or f.get('caption_printed')) if x))}",
"type: figure",
f"id: {f['id']}",
f"tipo: {f['type']}",
f"capitolo: {q(loc['chapter'])}",
f"sezione: {q(loc['section'])}",
f"tesi_loc: {q(tesi_loc)}",
f"composti: {lst(f.get('compounds', []))}",
f"concetti: {lst(f.get('concepts', []))}",
f"keywords: {lst(f.get('keywords', []))}",
f"confidence: {qual['confidence']}",
f"flags: {lst(qual.get('flags', []))}",
f"verifica: {v.get('verdict', 'n/d')}",
"derivata: true",
"---",
"",
]
body = [f"# {f['label']}", ""]
body += [f"**Didascalia stampata (testo della tesi):** {f.get('caption_printed') or 'n/d'}", ""]
cap = f", didascalia r.{loc['caption_md_line']}" if loc.get("caption_md_line") else ""
body += [f"_Posizione: tesi.md {tesi_loc} (sezione {loc['section']} {loc['section_title']}){cap}_", ""]
if "caption_mismatch" in qual.get("flags", []):
body += ["> ⚠ Flag `caption_mismatch`: la didascalia stampata qui sopra è quella attribuita dal catalogo e potrebbe non descrivere l'immagine (vedi «Didascalia generata» e «Da verificare»).", ""]
body += ["> Sotto: contenuto generato guardando l'immagine, non verificato una per una.", ""]
body += [f"**Didascalia generata:** {f['caption']}", ""]
for p in f["panels"]:
body += [p["embed"], ""]
body += [f"- Pannello: {p['panel'] or 'unico'} · file `{p['file']}` · {p['width']}×{p['height']} · confidence {p['confidence']}"]
body += [f"- Descrizione: {p['description']}"]
body += ["- Testo visibile: " + (" · ".join(p["visible_text"]) or "n/d")]
if p.get("quality_flags"):
body += ["- Flag: " + ", ".join(p["quality_flags"])]
body += [""]
if f.get("text_context"):
body += ["## Contesto nel testo", f["text_context"], ""]
if f.get("cited_in_md_lines"):
body += ["Citata in tesi.md alle righe: " + ", ".join(map(str, f["cited_in_md_lines"])), ""]
if qual.get("review_notes"):
body += ["## Da verificare", qual["review_notes"], ""]
if v.get("issues"):
body += ["Esito revisione indipendente: " + "; ".join(v["issues"]), ""]
body += ["## Collegamenti", "- [[tesi]]", ""]
(out / f"{f['id']}.md").write_text("\n".join(fm + body), encoding="utf8")
print(f"{len(cat['figures'])} note in {out}")
# --- wiki/figure-indice.md: indice derivato (sezione -> figure) ---
import re as _re
def _clean(s):
return _re.sub(r"<[^>]+>", "", s or "").strip()
idx = ["---", "title: Indice delle figure", "type: overview", "tags: [figure, indice, navigazione]",
"created: 2026-10-15", "updated: 2026-10-15", 'tesi_loc: "r.73-1301 (didascalie)"', "derivata: true", "status: draft", "---", "",
"# Indice delle figure", "",
f"Le {len(cat['figures'])} figure del catalogo raggruppate per sezione della tesi (generata da `raw/immagini.json`: non modificare a mano). "
"Ogni voce rimanda alla nota della figura; ⚠ = figura con flag o note di revisione. Matrice campioni × tecniche: [[campioni]]; tabelle: [[tabelle-indice]].", ""]
by_sec = {}
for f in cat["figures"]:
by_sec.setdefault(f["location"]["section"], []).append(f)
for s in cat["sections"]:
figs = by_sec.get(s["number"], [])
if not figs:
continue
idx += [f"## §{s['number']} {_clean(s['title'])}"]
for f in figs:
warn = " ⚠" if (f["quality"].get("flags") or f["quality"].get("review_notes")) else ""
if f["number"]:
idx.append(f"- [[{f['id']}|Fig. {f['number']}]] — {_clean(f['title'])} _({f['type']})_{warn}")
else:
idx.append(f"- [[{f['id']}|schema]] — {_clean(f['caption'])} _({f['type']})_{warn}")
idx.append("")
idx += ["## Collegamenti", "- [[index]] · [[tesi]] · [[campioni]] · [[tabelle-indice]]", ""]
(root / "wiki/figure-indice.md").write_text("\n".join(idx), encoding="utf8")
print("figure-indice.md generato")