From f34616ae3855657cd5c34d90ab6f3755250b05a7 Mon Sep 17 00:00:00 2001 From: maxime Date: Mon, 16 Nov 2026 13:20:31 +0100 Subject: [PATCH] The labeling scripts in scripts/ (validate, ids, precedents); the index stays in .index/ Co-Authored-By: Claude Opus 5.5 --- .claude/settings.json | 6 +++--- CLAUDE.md | 4 ++-- README.md | 6 +++--- ids.py => scripts/ids.py | 6 +++--- precedents.py => scripts/precedents.py | 10 +++++----- validate.py => scripts/validate.py | 12 ++++++------ 6 files changed, 22 insertions(+), 22 deletions(-) rename ids.py => scripts/ids.py (88%) rename precedents.py => scripts/precedents.py (94%) rename validate.py => scripts/validate.py (86%) diff --git a/.claude/settings.json b/.claude/settings.json index 62d09e9..41e239e 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -2,9 +2,9 @@ "$schema": "https://json.schemastore.org/claude-code-settings.json", "permissions": { "allow": [ - "Bash(python3 validate.py:*)", - "Bash(python3 ids.py:*)", - "Bash(python3 precedents.py:*)", + "Bash(python3 scripts/validate.py:*)", + "Bash(python3 scripts/ids.py:*)", + "Bash(python3 scripts/precedents.py:*)", "Bash(docker start ollama-bge-m3)" ], "deny": [ diff --git a/CLAUDE.md b/CLAUDE.md index 917c79e..df4a098 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,8 +4,8 @@ labeling: the AIMsight displacement labels and the knowledge to place them, in a - **The labels**: `manual/.jsonl` (the expert, for him alone), `auto/.jsonl` (the agents, reviewed by `review`), one per line, `{"id", "start", "end", "family", "description", ...}`. The Diagnostic-App analyses: `auto/analyses/__/`. - **The knowledge**, one source per kind (`README.md`), maintained by hand: `families.md` (the families, their boundaries, the catalogue of phenomena), `labeling-rules.md` (bounds, a single event, description, stated cause), `reading-rules.md` (what the data mean), `stations.md` (the installations); the cases are the labels, through `precedents.py`; what the data are: `tools/DATA.md`. A piece of knowledge lives in one of them only. -- **The tools**, standard library: `python3 validate.py [STATION | file.jsonl]` (the rules), `python3 ids.py [STATION]` (the stable id of new labels), `python3 precedents.py "" [--exclude STATION START END] [--family F] [--k N]` (the RAG; it starts the Ollama container `ollama-bge-m3` by itself if it does not answer; `--check` without it). -- **Verify**: `python3 validate.py` (today 19 expected errors: the labels submitted by the app without `review`) and `python3 precedents.py --check`. +- **The tools**, standard library: `python3 scripts/validate.py [STATION | file.jsonl]` (the rules), `python3 scripts/ids.py [STATION]` (the stable id of new labels), `python3 scripts/precedents.py "" [--exclude STATION START END] [--family F] [--k N]` (the RAG; it starts the Ollama container `ollama-bge-m3` by itself if it does not answer; `--check` without it). +- **Verify**: `python3 scripts/validate.py` (today 19 expected errors: the labels submitted by the app without `review`) and `python3 scripts/precedents.py --check`. Rules: - **`manual/` is the expert's, for him alone**: no agent and no process reads or writes there; the whole project (analyst, precedents, benchmark, optimization) uses only `auto/`. diff --git a/README.md b/README.md index 0604f58..91870a7 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ The AIMsight displacement labels and all the domain knowledge to place them, in | What the data mean: measurement chain, gaps, reading rules, false friends | `reading-rules.md` | | The installation of each station | `stations.md` | | What the data are: files, columns, image quality, images | `tools/DATA.md` (tools repository) | -- `validate.py` (the labels against the rules), `ids.py` (the stable id of each). -- `precedents.py`: the RAG of the labels. The labels of `auto/` closest in meaning to a text, with their provenance (reviewed or not); `--exclude STATION START END` leaves out the analyzed range. bge-m3 model of the Ollama container `ollama-bge-m3` (started by the script itself if it does not answer; port 11435); the `.index/` index, outside git, updates itself at every call (only new or modified labels go through the model; ~8 min to redo everything on CPU). +- `scripts/`: `validate.py` (the labels against the rules), `ids.py` (the stable id of each). +- `scripts/precedents.py`: the RAG of the labels. The labels of `auto/` closest in meaning to a text, with their provenance (reviewed or not); `--exclude STATION START END` leaves out the analyzed range. bge-m3 model of the Ollama container `ollama-bge-m3` (started by the script itself if it does not answer; port 11435); the `.index/` index, outside git, updates itself at every call (only new or modified labels go through the model; ~8 min to redo everything on CPU). -Diagnostic-App and Optimizer reach it through a link `labeling -> ~/labeling`, ignored by git: Diagnostic-App reads and writes there (labels, analyses), Optimizer only reads; commits are made here. `validate.py` and `ids.py` run from here or through the link (`python3 labeling/validate.py`). Descriptions are written in English from now on. +Diagnostic-App and Optimizer reach it through a link `labeling -> ~/labeling`, ignored by git: Diagnostic-App reads and writes there (labels, analyses), Optimizer only reads; commits are made here. The scripts run from here (`python3 scripts/validate.py`) or through the link (`python3 labeling/scripts/validate.py`). Descriptions are written in English from now on. History taken from Support-Agent (the `labeling/` folder, up to commit 48a3092), then the state of Diagnostic-App on 2026-11-13 (462ba9e): the archives of the etiqueteur and of the reviews (`auto/etiqueteur/`, `auto/revue/`, `auto/revue-croisee/`) and the old `labeling.py` tool remain in the history. diff --git a/ids.py b/scripts/ids.py similarity index 88% rename from ids.py rename to scripts/ids.py index ff893a0..e0a4d1c 100644 --- a/ids.py +++ b/scripts/ids.py @@ -1,7 +1,7 @@ """Stable identifier of the automatic labels (D-131): `-`, given once, never changed nor reused. -python3 labeling/ids.py # gives an id to the labels that have none, every station of labeling/auto/ -python3 labeling/ids.py NORDEND # one station +python3 labeling/scripts/ids.py # gives an id to the labels that have none, every station of labeling/auto/ +python3 labeling/scripts/ids.py NORDEND # one station A label keeps its id when it is changed; an added label receives the next one of its station. The id is always the first field of the line. The rest does not change (order of the lines, other fields). Standard library. @@ -11,7 +11,7 @@ import json import os import sys -AUTO = os.path.join(os.path.dirname(os.path.abspath(__file__)), "auto") # ~/labeling/auto, or through the labeling/ link +AUTO = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "auto") # ~/labeling/auto, or through the labeling/ link def id_first(e): diff --git a/precedents.py b/scripts/precedents.py similarity index 94% rename from precedents.py rename to scripts/precedents.py index cca2457..be99d66 100644 --- a/precedents.py +++ b/scripts/precedents.py @@ -4,10 +4,10 @@ uses it. The analyst describes what it sees on its range; the tool returns the labels already written that speak of it most, all stations, with their provenance (reviewed, not reviewed): it is up to the analyst to judge whether they fit its case. - python3 labeling/precedents.py "the targets jump together when a reference is rejected intermittently" - python3 labeling/precedents.py "" --exclude NORDEND 2026-11-04T21:12Z 2026-11-07T14:12Z --family Obstruction --k 5 - python3 labeling/precedents.py --index # only updates the index - python3 labeling/precedents.py --check # checks the logic, without Ollama + python3 labeling/scripts/precedents.py "the targets jump together when a reference is rejected intermittently" + python3 labeling/scripts/precedents.py "" --exclude NORDEND 2026-11-04T21:12Z 2026-11-07T14:12Z --family Obstruction --k 5 + python3 labeling/scripts/precedents.py --index # only updates the index + python3 labeling/scripts/precedents.py --check # checks the logic, without Ollama The index (.index/, out of git) keeps the vector of each text: at each call, only the new or changed labels go through the model. Model: bge-m3 served by Ollama, the ollama-bge-m3 container, which the tool starts by itself if it does not @@ -26,7 +26,7 @@ import urllib.request from datetime import datetime from pathlib import Path -HERE = Path(__file__).resolve().parent +HERE = Path(__file__).resolve().parent.parent # the labeling root: auto/ and .index/ URL = os.environ.get("OLLAMA_URL", "http://10.0.2.140:11435") # the port published by the ollama-bge-m3 container MODEL = os.environ.get("RAG_MODEL", "bge-m3:567m") CONTAINER = "ollama-bge-m3" # started by the tool if it does not answer diff --git a/validate.py b/scripts/validate.py similarity index 86% rename from validate.py rename to scripts/validate.py index 0fee989..8ba7ad9 100644 --- a/validate.py +++ b/scripts/validate.py @@ -1,11 +1,11 @@ """Validation of the automatic labels (labeling/auto/*.jsonl) against the rules of labeling/labeling-rules.md. -python3 labeling/validate.py # every station -python3 labeling/validate.py NORDEND # one station -python3 labeling/validate.py /labels.jsonl # a proposed file, before it is submitted (no `review` required) +python3 labeling/scripts/validate.py # every station +python3 labeling/scripts/validate.py NORDEND # one station +python3 labeling/scripts/validate.py /labels.jsonl # a proposed file, before it is submitted (no `review` required) Errors (to fix): unreadable JSON, missing field, unknown family, malformed date, start >= end, -label without `review` or without `id` (`python3 labeling/ids.py`), id not first in the line, duplicate id, exact duplicate, +label without `review` or without `id` (`python3 labeling/scripts/ids.py`), id not first in the line, duplicate id, exact duplicate, numeric value, local time, "probably not a movement". "Nothing to worry about" is right only with an established cause: to judge by reading, not by script. Flagged (to look at): overlaps of two labels of the same family on the same station. @@ -16,7 +16,7 @@ import os import re import sys -AUTO = os.path.join(os.path.dirname(os.path.abspath(__file__)), "auto") # ~/labeling/auto, or through the labeling/ link +AUTO = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "auto") # ~/labeling/auto, or through the labeling/ link FAMILIES = {"Visibility", "Obstruction", "Thermal displacement", "Displacement", "Target issue", "No data"} DATE = re.compile(r"^\d{4}-\d\d-\d\dT\d\d:\d\dZ$") @@ -44,7 +44,7 @@ for st in stations: errors.append(f"{where} missing field: {sorted(missing)}") if "id" in e: if next(iter(e)) != "id": - errors.append(f"{where} id not first in the line (`python3 labeling/ids.py`)") + errors.append(f"{where} id not first in the line (`python3 labeling/scripts/ids.py`)") if e["id"] in ids: errors.append(f"{where} duplicate id: {e['id']}") ids.add(e["id"])