data(taxonomie): M3 le mapping type × postures des 211 fiches, utils/taxonomie et son test (B4a)

- data/taxonomie/organisations.json : 91 org:<Id NocoDB> + 120 structure:<id>, type
  d'organisation et postures de la taxonomie N, une source par valeur.
- Règle : le type d'abord par les champs (type_org, nom, type_principal, première phrase
  de la description), autre quand rien ne tranche ; une posture seulement si un hashtag,
  une pensée, la famille ou la description la porte. README : la règle et comment
  corriger une entrée sur Gitea ; B4b la portera dans NocoDB.
- utils/taxonomie.ts (pur) : vocabulaire, libellés, classement avec repli autre,
  contrôle du mapping. useFicheAdapter : toMini(source, classer) pose type et postures.
- scripts/test-taxonomie.mjs (34 cas), dans npm run test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWGVn3kY4vPBaWF9EFkZbz
This commit is contained in:
Jules Neny
2026-11-03 14:54:23 +01:00
co-authored by Claude Opus 5.5
parent 951685ee47
commit 31f563684d
6 changed files with 2864 additions and 2 deletions
+107
View File
@@ -0,0 +1,107 @@
/**
* taxonomie — B4a-M3. Le type d'organisation et les postures de chaque fiche de la carte,
* lus dans `data/taxonomie/organisations.json` (une entrée par identifiant : `org:<Id NocoDB>`,
* `structure:<id>`). Vocabulaire : la taxonomie N (`Cadrage/N-prompt-session-taxonomie-carte-unifiee.md`).
*
* Pur (aucune dépendance à Vue ni au routeur) : `scripts/test-taxonomie.mjs` le teste,
* `pages/index.vue` le passe à `toMini` (useFicheAdapter) qui en fait les étiquettes `type`
* et `postures` de chaque fiche.
*
* B4b portera ces deux champs dans NocoDB (`type_organisation`, `postures`) : les clés du
* fichier sont les identifiants stables des deux bases, rien d'autre ne change de forme.
*/
import mapping from '../data/taxonomie/organisations.json'
export const TYPES_ORGANISATION = ['institution', 'association', 'syndicat', 'agence', 'formation', 'media', 'autre'] as const
export type TypeOrganisation = (typeof TYPES_ORGANISATION)[number]
export const POSTURES = ['regenerative', 'bas-carbone', 'cooperative', 'patrimoine', 'ecoconstruction', 'low-tech', 'participatif'] as const
export type Posture = (typeof POSTURES)[number]
/** Libellés des chips (valeur d'URL → texte). */
export const LIBELLES_TYPE: Record<TypeOrganisation, string> = {
institution: 'Institution',
association: 'Association',
syndicat: 'Syndicat',
agence: 'Agence',
formation: 'Formation',
media: 'Média',
autre: 'Autre',
}
export const LIBELLES_POSTURE: Record<Posture, string> = {
regenerative: 'Régénératif',
'bas-carbone': 'Bas carbone',
cooperative: 'Coopératif',
patrimoine: 'Patrimoine',
ecoconstruction: 'Écoconstruction',
'low-tech': 'Low-tech',
participatif: 'Participatif',
}
/** Une entrée du fichier. `nom` n'est là que pour qui corrige le fichier à la main. */
export interface EntreeTaxonomie {
nom?: string
type_organisation: string
postures: string[]
source: { type_organisation: string; postures: Record<string, string> }
}
export interface MappingTaxonomie {
version: number
entrees: Record<string, EntreeTaxonomie>
}
/** Ce qu'une fiche porte, toujours dans le vocabulaire. */
export interface Classement {
type: TypeOrganisation
postures: Posture[]
}
export const MAPPING = mapping as MappingTaxonomie
export const idOrg = (id: number | string) => `org:${id}`
export const idStructure = (id: string) => `structure:${id}`
const estType = (v: unknown): v is TypeOrganisation => (TYPES_ORGANISATION as readonly string[]).includes(v as string)
const estPosture = (v: unknown): v is Posture => (POSTURES as readonly string[]).includes(v as string)
/**
* Classement d'un identifiant. Repli : un identifiant absent (fiche ajoutée après le
* mapping) ou un type hors vocabulaire vaut `autre` ; une posture hors vocabulaire ou
* sans source est ignorée (une posture ne s'affiche que si sa source est écrite).
*/
export function classement(id: string, m: MappingTaxonomie = MAPPING): Classement {
const e = m.entrees[id]
if (!e) return { type: 'autre', postures: [] }
const sources = e.source?.postures ?? {}
const postures = POSTURES.filter((p) => (e.postures ?? []).includes(p) && !!sources[p])
return { type: estType(e.type_organisation) ? e.type_organisation : 'autre', postures }
}
/**
* Écarts d'un mapping à la règle (liste vide = conforme) : type et postures dans le
* vocabulaire, une source pour le type et pour chaque posture, pas de posture en double.
*/
export function ecartsMapping(m: MappingTaxonomie): string[] {
const out: string[] = []
for (const [id, e] of Object.entries(m.entrees)) {
if (!/^(org:\d+|structure:[a-z0-9-]+)$/.test(id)) out.push(`${id} : identifiant hors forme (org:<Id> ou structure:<id>)`)
if (!estType(e.type_organisation)) out.push(`${id} : type « ${e.type_organisation} » hors vocabulaire`)
if (!e.source?.type_organisation?.trim()) out.push(`${id} : type sans source`)
const ps = e.postures ?? []
if (new Set(ps).size !== ps.length) out.push(`${id} : posture en double`)
for (const p of ps) {
if (!estPosture(p)) out.push(`${id} : posture « ${p} » hors vocabulaire`)
if (!e.source?.postures?.[p]?.trim()) out.push(`${id} : posture « ${p} » sans source`)
}
for (const p of Object.keys(e.source?.postures ?? {})) if (!ps.includes(p)) out.push(`${id} : source pour « ${p} », absente de postures`)
}
return out
}
/** Valeurs d'une dimension présentes dans des fiches, dans l'ordre du vocabulaire (chips sans zéro). */
export function valeursPresentes<T extends string>(vocabulaire: readonly T[], libelles: Record<T, string>, portees: Iterable<string>): { valeur: T; libelle: string }[] {
const vues = new Set(portees)
return vocabulaire.filter((v) => vues.has(v)).map((v) => ({ valeur: v, libelle: libelles[v] }))
}