- Every auto label carries an id (<STATION>-<n>, labeling/ids.py), kept on edit, given to new labels by labeling.py and by the reviews; controle.py requires it, unique. The cross-review matches labels by id, and an applied review is locked (applique.md). - The label map starts with a summary (labels-map/sommaire.py): readers take the summary and sections 2-4 in full, then only the cards of the phenomena they meet. - Tool-builder session on the reviewers' difficulties: jours.py --lissage/--fraction, ensemble.py --suivre and rejected measures left out of --rigide, --residus non, zero noise after a lost reference, new agent-tools/stations.py (several stations on one timeline), long outputs convention in lire-les-donnees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
2.3 KiB
Python
46 lines
2.3 KiB
Python
"""Sommaire de la carte des étiquettes (skill labels-map) : une ligne par fiche, avec sa ligne dans le fichier,
|
|
pour qu'un lecteur lise le sommaire et les sections 2 à 4, puis seulement les fiches qui le concernent.
|
|
|
|
python3 .claude/skills/labels-map/sommaire.py # (ré)écrit le bloc entre <!-- sommaire --> et <!-- /sommaire -->
|
|
|
|
La ligne d'une fiche : son titre, la première phrase de « Ce qui se passe », et `l. N` (Read avec offset N).
|
|
"""
|
|
import re
|
|
|
|
P = "labeling/carte-des-etiquettes.md"
|
|
DEBUT, FIN = "<!-- sommaire -->", "<!-- /sommaire -->"
|
|
|
|
texte = open(P, encoding="utf-8").read()
|
|
if DEBUT in texte: # l'ancien bloc s'enlève d'abord, il se refait
|
|
avant, reste = texte.split(DEBUT, 1)
|
|
texte = avant.rstrip("\n") + "\n\n" + reste.split(FIN, 1)[1].lstrip("\n")
|
|
lignes = texte.split("\n")
|
|
ancre = next(i for i, l in enumerate(lignes) if l.startswith("## 1."))
|
|
|
|
|
|
def bloc(decalage):
|
|
out = [DEBUT, "## Sommaire", "",
|
|
"Lire le sommaire et les sections 2 à 4 en entier, puis la fiche de chaque phénomène rencontré (Read avec `offset` à sa ligne).", ""]
|
|
for i, l in enumerate(lignes):
|
|
if l.startswith("### ") and i > ancre and not l.startswith("### Les règles") and not l.startswith("### Celles"):
|
|
out.append(f"- **{l[4:]}**")
|
|
elif l.startswith("#### "):
|
|
suite = "\n".join(lignes[i + 1:i + 6])
|
|
m = re.search(r"\*\*Ce qui se passe\*\*\s*:\s*(.+?[.;])(\s|$)", suite)
|
|
out.append(f" - {l[5:]} (l. {i + 1 + decalage})" + (f" : {m.group(1)}" if m else ""))
|
|
for i, l in enumerate(lignes):
|
|
if l.startswith("## ") and i > ancre and not l.startswith("## 1."):
|
|
out.append(f"- **{l[3:]}** (l. {i + 1 + decalage})")
|
|
return out + [FIN, ""]
|
|
|
|
|
|
n = len(bloc(0)) # le bloc s'insère avant « ## 1. » : les fiches descendent de sa longueur
|
|
nouveau = lignes[:ancre] + bloc(n) + lignes[ancre:]
|
|
open(P, "w", encoding="utf-8").write("\n".join(nouveau))
|
|
final = open(P, encoding="utf-8").read().split("\n")
|
|
for l in bloc(n): # contrôle : chaque `l. N` tombe sur son titre
|
|
m = re.search(r"^\s*- (?:\*\*)?(.+?)(?:\*\*)? \(l\. (\d+)\)", l)
|
|
if m:
|
|
assert final[int(m.group(2)) - 1].lstrip("#").strip() == m.group(1), l
|
|
print(sum(1 for l in bloc(n) if "(l. " in l), "entrées ;", len(final), "lignes")
|