refactor(connaissances): dette de la page, domaine sorti dans utils/connaissances (B19b M4)
- graphe.ts : disposer, disposerEnCache, voisinage (mêmes signatures) et boite, sortis de GrapheConnaissances.vue ; la boîte du monde se calcule une fois par layout. - lire.ts : lecture (index du jeu mémorisé), sourcesDe, porteursDe, relationsDe, relationsParLibelle, dettesDe, vacancesDe, LIBELLES_RELATION, estRendu, sortis de la page. - vocabulaire.ts : natures, préfixes, échelles, couches, états, seuil de copie et libellés, écrits une fois et comparés au schéma par le test ; valider.ts les importe et les réexporte. - Types : ObjetConnaissance / JeuConnaissances (valider.ts) seuls ; ObjetCouche / JeuCouche retirés de l'adaptateur ; la page lit un computed typé objetOuvert. - toMiniConnaissance ne reconstruit plus la carte des objets à chaque appel ; le degré des nœuds n'est plus calculé deux fois (le graphe le calcule seul). - Tokens existants à la place des valeurs en dur (--fs-*, --dur-fast, --radius-*), .cn-sr remplacé par sr-only (Tailwind, servi sur la page). - test-connaissances : 92 → 130 cas. HTML de la page identique avant / après hors classes sr-only et CSS (positions du graphe comprises). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWGVn1RZVsSd6YYS1o7CHk
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
be8206d25b
commit
448752f994
@@ -20,7 +20,8 @@
|
||||
Layout : force simple à graine fixe, calculé depuis nœuds et liens (aucune position en
|
||||
données), mis en cache par signature du graphe (une fois par processus serveur), puis
|
||||
projeté sur la taille mesurée. Liens : trait plein = énoncé par la source, tirets = posé
|
||||
par la curation.
|
||||
par la curation. La géométrie (disposer, cache, voisinage, boîte) vit dans
|
||||
`utils/connaissances/graphe.ts`, testée (B19b M4).
|
||||
-->
|
||||
<template>
|
||||
<div ref="racine" class="gc" :class="{ 'gc--fige': fige }">
|
||||
@@ -89,145 +90,9 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
/** Un nœud : `kind` dit sa forme (principal si dans `kindsPrincipaux`, sinon secondaire). */
|
||||
export interface NoeudGraphe { id: string; libelle: string; kind: string; poids?: number }
|
||||
export interface LienGraphe { de: string; vers: string; type: string; provenance: string }
|
||||
export type Pas = 1 | 2 | 'tout'
|
||||
|
||||
type Pt = { x: number; y: number }
|
||||
|
||||
/** PRNG à graine fixe (mulberry32) : même graphe, même dessin, au serveur comme au navigateur. */
|
||||
function alea(graine: number) {
|
||||
let a = graine >>> 0
|
||||
return () => {
|
||||
a = (a + 0x6d2b79f5) >>> 0
|
||||
let t = a
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1)
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force simple (Fruchterman-Reingold), graine fixe, nombre de pas fixe : positions dans un
|
||||
* repère sans unité, centré, d'étendue 1. Fonction pure de (nœuds, liens, principaux).
|
||||
*/
|
||||
export function disposer(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
|
||||
const n = noeuds.length
|
||||
const pos = new Map<string, Pt>()
|
||||
if (!n) return pos
|
||||
const rnd = alea(0x9e3779b9)
|
||||
const index = new Map(noeuds.map((x, i) => [x.id, i]))
|
||||
const aretes = liens
|
||||
.map((l) => [index.get(l.de), index.get(l.vers)] as const)
|
||||
.filter((a): a is readonly [number, number] => a[0] != null && a[1] != null && a[0] !== a[1])
|
||||
const voisins: number[][] = noeuds.map(() => [])
|
||||
for (const [a, b] of aretes) { voisins[a].push(b); voisins[b].push(a) }
|
||||
|
||||
// Départ : les principaux en cercle, chaque secondaire au barycentre de ses voisins principaux.
|
||||
const prin = noeuds.map((x, i) => (principaux.has(x.kind) ? i : -1)).filter((i) => i >= 0)
|
||||
const X = new Float64Array(n)
|
||||
const Y = new Float64Array(n)
|
||||
prin.forEach((i, k) => {
|
||||
const t = (2 * Math.PI * k) / Math.max(prin.length, 1)
|
||||
X[i] = 0.4 * Math.cos(t)
|
||||
Y[i] = 0.4 * Math.sin(t)
|
||||
})
|
||||
noeuds.forEach((x, i) => {
|
||||
if (principaux.has(x.kind)) return
|
||||
const v = voisins[i].filter((j) => principaux.has(noeuds[j].kind))
|
||||
if (v.length) {
|
||||
X[i] = (v.reduce((s, j) => s + X[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
|
||||
Y[i] = (v.reduce((s, j) => s + Y[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
|
||||
} else {
|
||||
X[i] = (rnd() - 0.5) * 0.9
|
||||
Y[i] = (rnd() - 0.5) * 0.9
|
||||
}
|
||||
})
|
||||
|
||||
const k = 0.9 * Math.sqrt(1 / n)
|
||||
const ITER = 350
|
||||
const dx = new Float64Array(n)
|
||||
const dy = new Float64Array(n)
|
||||
for (let it = 0; it < ITER; it++) {
|
||||
const temp = 0.08 * (1 - it / ITER) + 0.002
|
||||
dx.fill(0)
|
||||
dy.fill(0)
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let j = i + 1; j < n; j++) {
|
||||
let ex = X[i] - X[j]
|
||||
let ey = Y[i] - Y[j]
|
||||
let d = Math.hypot(ex, ey)
|
||||
if (d < 1e-4) { ex = (rnd() - 0.5) * 1e-3; ey = (rnd() - 0.5) * 1e-3; d = Math.hypot(ex, ey) }
|
||||
const f = (k * k) / d
|
||||
dx[i] += (ex / d) * f; dy[i] += (ey / d) * f
|
||||
dx[j] -= (ex / d) * f; dy[j] -= (ey / d) * f
|
||||
}
|
||||
}
|
||||
for (const [a, b] of aretes) {
|
||||
const ex = X[a] - X[b]
|
||||
const ey = Y[a] - Y[b]
|
||||
const d = Math.max(Math.hypot(ex, ey), 1e-4)
|
||||
const f = (d * d) / k
|
||||
dx[a] -= (ex / d) * f; dy[a] -= (ey / d) * f
|
||||
dx[b] += (ex / d) * f; dy[b] += (ey / d) * f
|
||||
}
|
||||
for (let i = 0; i < n; i++) {
|
||||
dx[i] -= X[i] * 0.9 * k * 4
|
||||
dy[i] -= Y[i] * 0.9 * k * 4
|
||||
const d = Math.hypot(dx[i], dy[i])
|
||||
if (d > 0) {
|
||||
const m = Math.min(d, temp)
|
||||
X[i] += (dx[i] / d) * m
|
||||
Y[i] += (dy[i] / d) * m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Centré, étendue 1 (le plus grand côté de la boîte englobante)
|
||||
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
|
||||
for (let i = 0; i < n; i++) { x0 = Math.min(x0, X[i]); x1 = Math.max(x1, X[i]); y0 = Math.min(y0, Y[i]); y1 = Math.max(y1, Y[i]) }
|
||||
const e = Math.max(x1 - x0, y1 - y0) || 1
|
||||
noeuds.forEach((x, i) => pos.set(x.id, { x: (X[i] - (x0 + x1) / 2) / e, y: (Y[i] - (y0 + y1) / 2) / e }))
|
||||
return pos
|
||||
}
|
||||
|
||||
/** Cache par signature du graphe : au serveur, une fois par processus, pas une fois par requête. */
|
||||
const CACHE = new Map<string, Map<string, Pt>>()
|
||||
export function disposerEnCache(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
|
||||
const sig = JSON.stringify([noeuds.map((x) => [x.id, x.kind]), liens.map((l) => [l.de, l.vers]), [...principaux]])
|
||||
let p = CACHE.get(sig)
|
||||
if (!p) {
|
||||
p = disposer(noeuds, liens, principaux)
|
||||
if (CACHE.size > 24) CACHE.delete(CACHE.keys().next().value as string)
|
||||
CACHE.set(sig, p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
/** Identifiants à `pas` liens au plus de `id` (le nœud compris) ; `tout` = tous. */
|
||||
export function voisinage(liens: LienGraphe[], id: string, pas: Pas): Set<string> | null {
|
||||
if (pas === 'tout') return null
|
||||
const adj = new Map<string, string[]>()
|
||||
for (const l of liens) {
|
||||
if (!adj.has(l.de)) adj.set(l.de, [])
|
||||
if (!adj.has(l.vers)) adj.set(l.vers, [])
|
||||
adj.get(l.de)!.push(l.vers)
|
||||
adj.get(l.vers)!.push(l.de)
|
||||
}
|
||||
const vus = new Set([id])
|
||||
let front = [id]
|
||||
for (let p = 0; p < pas; p++) {
|
||||
const suite: string[] = []
|
||||
for (const x of front) for (const y of adj.get(x) ?? []) if (!vus.has(y)) { vus.add(y); suite.push(y) }
|
||||
front = suite
|
||||
}
|
||||
return vus
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { boite, disposerEnCache, voisinage, type LienGraphe, type NoeudGraphe, type Pas, type Pt } from '~/utils/connaissances/graphe'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
noeuds: NoeudGraphe[]
|
||||
liens: LienGraphe[]
|
||||
@@ -311,13 +176,13 @@ const zone = computed(() => {
|
||||
const m = taille.w < 768 ? MARGE_TEL : MARGE
|
||||
return { x: m.gauche, y: m.haut, w: Math.max(40, taille.w - m.gauche - m.droite), h: Math.max(40, taille.h - m.haut - m.bas) }
|
||||
})
|
||||
/** Portrait d'écran et dessin paysage (ou l'inverse) : on tourne le dessin d'un quart. Projection, rien en base. */
|
||||
const tourne = computed(() => {
|
||||
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
|
||||
for (const p of monde.value.values()) { x0 = Math.min(x0, p.x); x1 = Math.max(x1, p.x); y0 = Math.min(y0, p.y); y1 = Math.max(y1, p.y) }
|
||||
const paysage = x1 - x0 >= y1 - y0
|
||||
return paysage !== zone.value.w >= zone.value.h
|
||||
/** Le dessin est-il en paysage ? Calculé une fois par layout (le monde est en cache), pas à chaque redimensionnement. */
|
||||
const paysage = computed(() => {
|
||||
const b = boite(monde.value.values())
|
||||
return b.x1 - b.x0 >= b.y1 - b.y0
|
||||
})
|
||||
/** Portrait d'écran et dessin paysage (ou l'inverse) : on tourne le dessin d'un quart. Projection, rien en base. */
|
||||
const tourne = computed(() => paysage.value !== zone.value.w >= zone.value.h)
|
||||
const pt = (id: string): Pt | null => {
|
||||
const p = monde.value.get(id)
|
||||
if (!p) return null
|
||||
@@ -326,13 +191,11 @@ const pt = (id: string): Pt | null => {
|
||||
|
||||
const cible = computed<Camera>(() => {
|
||||
const vis = visibles.value
|
||||
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
|
||||
for (const x of props.noeuds) {
|
||||
if (vis && !vis.has(x.id)) continue
|
||||
const p = pt(x.id)
|
||||
if (!p) continue
|
||||
x0 = Math.min(x0, p.x); x1 = Math.max(x1, p.x); y0 = Math.min(y0, p.y); y1 = Math.max(y1, p.y)
|
||||
}
|
||||
const points = props.noeuds
|
||||
.filter((x) => !vis || vis.has(x.id))
|
||||
.map((x) => pt(x.id))
|
||||
.filter((p): p is Pt => !!p)
|
||||
const { x0, x1, y0, y1 } = boite(points)
|
||||
if (!Number.isFinite(x0)) return { cx: 0, cy: 0, s: 1 }
|
||||
const z = zone.value
|
||||
const plein = Math.min(z.w, z.h) // échelle du graphe entier (étendue 1)
|
||||
@@ -477,14 +340,14 @@ const liensVus = computed(() => props.liens
|
||||
.gc__lien {
|
||||
stroke: color-mix(in srgb, var(--text) 38%, transparent);
|
||||
stroke-width: 1.1;
|
||||
transition: stroke 160ms ease-out, stroke-width 160ms ease-out, opacity 160ms ease-out;
|
||||
transition: stroke var(--dur-fast) ease-out, stroke-width var(--dur-fast) ease-out, opacity var(--dur-fast) ease-out;
|
||||
}
|
||||
.gc__lien--curation { stroke-dasharray: 4 3; }
|
||||
.gc__lien--vif { stroke: var(--text); stroke-width: 1.8; }
|
||||
.gc__lien--eteint { opacity: 0.25; }
|
||||
|
||||
/* Sources : carrés gris, hors tabulation (au clavier, on y va par la liste des fiches) */
|
||||
.gc__source { cursor: pointer; transition: opacity 160ms ease-out; }
|
||||
.gc__source { cursor: pointer; transition: opacity var(--dur-fast) ease-out; }
|
||||
.gc__carre {
|
||||
fill: color-mix(in srgb, var(--text) 52%, var(--bg-alt));
|
||||
stroke: var(--bg-alt);
|
||||
@@ -496,8 +359,8 @@ const liensVus = computed(() => props.liens
|
||||
.gc__source--loin { opacity: 0.6; }
|
||||
.gc__source-texte {
|
||||
fill: color-mix(in srgb, var(--text) 80%, transparent);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
font-size: var(--fs-xs);
|
||||
font-weight: var(--fw-medium);
|
||||
paint-order: stroke;
|
||||
stroke: var(--bg-alt);
|
||||
stroke-width: 3px;
|
||||
@@ -523,7 +386,7 @@ const liensVus = computed(() => props.liens
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
transition: opacity 160ms ease-out;
|
||||
transition: opacity var(--dur-fast) ease-out;
|
||||
}
|
||||
.gc__rond {
|
||||
width: calc(2 * var(--gc-r));
|
||||
@@ -531,16 +394,16 @@ const liensVus = computed(() => props.liens
|
||||
border-radius: 50%;
|
||||
background: var(--surface);
|
||||
border: 2px solid var(--text);
|
||||
transition: background 160ms ease-out, border-color 160ms ease-out;
|
||||
transition: background var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out;
|
||||
}
|
||||
.gc__libelle {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
font-size: var(--fs-xs);
|
||||
font-weight: var(--fw-semibold);
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
overflow-wrap: anywhere;
|
||||
padding: 0 3px;
|
||||
border-radius: 4px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--bg-alt) 82%, transparent);
|
||||
}
|
||||
.gc__noeud--survol .gc__rond { border-width: 3px; }
|
||||
@@ -598,7 +461,6 @@ const liensVus = computed(() => props.liens
|
||||
@media (max-width: 639.98px) { .gc__legende { display: none; } }
|
||||
@media (max-width: 767.98px) {
|
||||
.gc__noeud { max-width: 8rem; }
|
||||
.gc__libelle { font-size: 12px; }
|
||||
}
|
||||
|
||||
/* Mouvement réduit : état final, sans transition (la caméra saute aussi, côté script) */
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
import type { Org } from '~/types/org'
|
||||
import type { StructureV2 } from '~/types/structure-v2'
|
||||
import type { JeuConnaissances, ObjetConnaissance } from '../utils/connaissances/valider'
|
||||
import { lecture, porteursDe, estRendu, type Lecture } from '../utils/connaissances/lire'
|
||||
import { ECHELLES, LIBELLES_NATURE, RE_PREFIXE } from '../utils/connaissances/vocabulaire'
|
||||
|
||||
export interface MiniFiche {
|
||||
id: string | number
|
||||
@@ -194,65 +197,21 @@ export function toMiniMot(fiche: FicheMot, ressources: RessourceMot[]): MiniFich
|
||||
}
|
||||
|
||||
// ── Connaissances partagées (B19-M1) : un objet de la couche = une fiche ──────
|
||||
|
||||
/**
|
||||
* Un objet de `data/connaissances/` (schéma B18). Type local, volontairement lâche :
|
||||
* le contrat fait foi dans `data/connaissances/schema.json`, le contrôle dans
|
||||
* `utils/connaissances/valider.ts`.
|
||||
*/
|
||||
export interface ObjetCouche {
|
||||
id: string
|
||||
nature: 'texte' | 'organisation' | 'outil' | 'concept'
|
||||
nom_canonique: string
|
||||
etat: string
|
||||
definition_courte?: string
|
||||
libelle_source?: string
|
||||
variantes?: string[]
|
||||
porteur_ids?: string[]
|
||||
echelles?: string[]
|
||||
couche?: string
|
||||
date_original?: string | null
|
||||
credit?: string | null
|
||||
[champ: string]: unknown
|
||||
}
|
||||
export interface JeuCouche {
|
||||
objets: ObjetCouche[]
|
||||
relations: { type: string; de: string; vers: string; provenance: string; etat: string; note?: string }[]
|
||||
[champ: string]: unknown
|
||||
}
|
||||
|
||||
export const LIBELLES_NATURE: Record<ObjetCouche['nature'], string> = {
|
||||
concept: 'Concept',
|
||||
texte: 'Texte',
|
||||
organisation: 'Organisation',
|
||||
outil: 'Outil',
|
||||
}
|
||||
|
||||
/**
|
||||
* Ce que la page rend : les objets publiés. Un objet écarté reste en base et n'est jamais
|
||||
* rendu ; `en_file`, `a_trier` et `a_creuser` non plus, tant qu'un humain n'a pas tranché
|
||||
* (interdit n° 2 de la CONCEPTION §5).
|
||||
*/
|
||||
export const estRendu = (o: { etat: string }) => o.etat === 'publie'
|
||||
// Types : `utils/connaissances/valider.ts` (les seuls de la couche). Vocabulaire :
|
||||
// `utils/connaissances/vocabulaire.ts`. Lecture du jeu (index, porteurs) : `lire.ts`.
|
||||
|
||||
/** `org:holosapiens` → `holosapiens` : la forme d'un porteur dans l'URL (`porteur=holosapiens`). */
|
||||
export const valeurPorteur = (id: string) => id.replace(/^[a-z]+:/, '')
|
||||
|
||||
/** Porteurs d'un objet : ses `porteur_ids` qui sont des organisations rendues ; une organisation se porte elle-même. */
|
||||
function porteursDe(o: ObjetCouche, rendus: Map<string, ObjetCouche>): ObjetCouche[] {
|
||||
if (o.nature === 'organisation') return [o]
|
||||
return (o.porteur_ids ?? []).map((id) => rendus.get(id)).filter((p): p is ObjetCouche => !!p && p.nature === 'organisation')
|
||||
}
|
||||
export const valeurPorteur = (id: string) => id.replace(RE_PREFIXE, '')
|
||||
|
||||
/** Échelles d'un objet : les siennes ; pour une source, celles des concepts publiés qui en sont extraits (projection, rien en base). */
|
||||
function echellesDe(o: ObjetCouche, jeu: JeuCouche, rendus: Map<string, ObjetCouche>): string[] {
|
||||
function echellesDe(o: ObjetConnaissance, l: Lecture): string[] {
|
||||
if (o.echelles?.length) return [...o.echelles]
|
||||
const out = new Set<string>()
|
||||
for (const r of jeu.relations) {
|
||||
for (const r of l.jeu.relations) {
|
||||
if (r.type !== 'extrait_de' || r.vers !== o.id) continue
|
||||
for (const e of rendus.get(r.de)?.echelles ?? []) out.add(e)
|
||||
for (const e of l.rendus.get(r.de)?.echelles ?? []) out.add(e)
|
||||
}
|
||||
return ['S', 'M', 'XL'].filter((e) => out.has(e))
|
||||
return ECHELLES.filter((e) => out.has(e))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,10 +220,11 @@ function echellesDe(o: ObjetCouche, jeu: JeuCouche, rendus: Map<string, ObjetCou
|
||||
* Pas de géographie : `geoloc: true`, comme `toMiniMot` (sinon la vue annoncerait « N sans
|
||||
* adresse » et n'offrirait pas « Voir dans le graphe »).
|
||||
*/
|
||||
export function toMiniConnaissance(objet: ObjetCouche, jeu: JeuCouche): MiniFiche {
|
||||
const rendus = new Map(jeu.objets.filter(estRendu).map((o) => [o.id, o]))
|
||||
const porteurs = porteursDe(objet, rendus)
|
||||
const echelles = echellesDe(objet, jeu, rendus)
|
||||
export function toMiniConnaissance(objet: ObjetConnaissance, jeu: JeuConnaissances): MiniFiche {
|
||||
// L'index du jeu est construit une fois par jeu (`lecture`, mémorisé), pas une fois par fiche.
|
||||
const l = lecture(jeu)
|
||||
const porteurs = porteursDe(l, objet)
|
||||
const echelles = echellesDe(objet, l)
|
||||
const nomsPorteurs = porteurs.filter((p) => p.id !== objet.id).map((p) => p.nom_canonique)
|
||||
// Une organisation se porte elle-même : « titre — porteur » redirait son nom ; on dit son statut et son adresse.
|
||||
const domaine = typeof objet.url_canonique === 'string' ? objet.url_canonique.replace(/^https?:\/\/(www\.)?/, '').replace(/\/.*$/, '') : ''
|
||||
@@ -295,26 +255,24 @@ export function toMiniConnaissance(objet: ObjetCouche, jeu: JeuCouche): MiniFich
|
||||
}
|
||||
|
||||
/** Les fiches de la page : objets publiés, dans l'ordre du jeu. */
|
||||
export function fichesConnaissances(jeu: JeuCouche): MiniFiche[] {
|
||||
return jeu.objets.filter(estRendu).map((o) => toMiniConnaissance(o, jeu))
|
||||
export function fichesConnaissances(jeu: JeuConnaissances): MiniFiche[] {
|
||||
return [...lecture(jeu).rendus.values()].map((o) => toMiniConnaissance(o, jeu))
|
||||
}
|
||||
|
||||
/**
|
||||
* Nœuds et liens du graphe, depuis les seuls objets publiés et les relations publiées
|
||||
* entre eux (`renvoie_a` et les porteurs du registre restent hors du graphe : ils visent
|
||||
* une autre base). Aucune position : `GrapheConnaissances` la calcule.
|
||||
* une autre base). Aucune position ni degré : `GrapheConnaissances` les calcule, une fois.
|
||||
*/
|
||||
export function grapheConnaissances(jeu: JeuCouche): {
|
||||
noeuds: { id: string; libelle: string; kind: string; poids: number }[]
|
||||
export function grapheConnaissances(jeu: JeuConnaissances): {
|
||||
noeuds: { id: string; libelle: string; kind: string }[]
|
||||
liens: { de: string; vers: string; type: string; provenance: string }[]
|
||||
} {
|
||||
const rendus = new Map(jeu.objets.filter(estRendu).map((o) => [o.id, o]))
|
||||
const { rendus } = lecture(jeu)
|
||||
const liens = jeu.relations
|
||||
.filter((r) => r.etat === 'publie' && r.type !== 'renvoie_a' && rendus.has(r.de) && rendus.has(r.vers))
|
||||
.filter((r) => estRendu(r) && r.type !== 'renvoie_a' && rendus.has(r.de) && rendus.has(r.vers))
|
||||
.map((r) => ({ de: r.de, vers: r.vers, type: r.type, provenance: r.provenance }))
|
||||
const degre = new Map<string, number>()
|
||||
for (const l of liens) for (const id of [l.de, l.vers]) degre.set(id, (degre.get(id) ?? 0) + 1)
|
||||
const noeuds = [...rendus.values()].map((o) => ({ id: o.id, libelle: o.nom_canonique, kind: o.nature, poids: degre.get(o.id) ?? 0 }))
|
||||
const noeuds = [...rendus.values()].map((o) => ({ id: o.id, libelle: o.nom_canonique, kind: o.nature }))
|
||||
return { noeuds, liens }
|
||||
}
|
||||
|
||||
|
||||
+58
-102
@@ -16,7 +16,7 @@
|
||||
Premier jeu : {{ nombreEnLettres(nbConcepts) }} concepts et leurs sources.
|
||||
La couche se nourrit des ressources proposées par les membres, triées à la main.
|
||||
Navigation inspirée de
|
||||
<a href="https://holosapiens.earth" target="_blank" rel="noopener noreferrer">l’explorateur Holosapiens<span class="cn-sr"> (nouvel onglet)</span></a>
|
||||
<a href="https://holosapiens.earth" target="_blank" rel="noopener noreferrer">l’explorateur Holosapiens<span class="sr-only"> (nouvel onglet)</span></a>
|
||||
(CC BY-SA 4.0).
|
||||
</p>
|
||||
</header>
|
||||
@@ -44,9 +44,9 @@
|
||||
</template>
|
||||
|
||||
<template #detail="{ fiche, filtrer }">
|
||||
<article v-if="objetDe(fiche.id)" class="cf">
|
||||
<p class="cf__nature">{{ LIBELLES_NATURE[objetDe(fiche.id)!.nature] }}</p>
|
||||
<h2 class="cf__titre">{{ objetDe(fiche.id)!.nom_canonique }}</h2>
|
||||
<article v-if="objetOuvert" class="cf">
|
||||
<p class="cf__nature">{{ LIBELLES_NATURE[objetOuvert.nature] }}</p>
|
||||
<h2 class="cf__titre">{{ objetOuvert.nom_canonique }}</h2>
|
||||
|
||||
<ChipGroup v-if="fiche.etiquettes?.echelle?.length" :aria-label="`Échelles de ${fiche.nom}`" class="cf__chips">
|
||||
<Chip
|
||||
@@ -61,37 +61,37 @@
|
||||
</ChipGroup>
|
||||
|
||||
<!-- Concept : la définition, dans nos mots -->
|
||||
<template v-if="objetDe(fiche.id)!.nature === 'concept'">
|
||||
<p class="cf__definition">{{ objetDe(fiche.id)!.definition_courte }}</p>
|
||||
<template v-if="objetOuvert.nature === 'concept'">
|
||||
<p class="cf__definition">{{ objetOuvert.definition_courte }}</p>
|
||||
<p class="cf__mention">Définition écrite par AEP, dans ses mots.</p>
|
||||
</template>
|
||||
|
||||
<!-- Objet : date de l'original, lien sortant -->
|
||||
<dl v-else class="cf__faits">
|
||||
<template v-if="objetDe(fiche.id)!.date_original">
|
||||
<dt>{{ objetDe(fiche.id)!.date_original_nature === 'vue' ? 'En ligne au' : 'Date de l’original' }}</dt>
|
||||
<template v-if="objetOuvert.date_original">
|
||||
<dt>{{ objetOuvert.date_original_nature === 'vue' ? 'En ligne au' : 'Date de l’original' }}</dt>
|
||||
<dd>
|
||||
{{ dateFr(objetDe(fiche.id)!.date_original) }}
|
||||
<span v-if="objetDe(fiche.id)!.date_original_nature === 'vue'" class="cf__discret">(aucune date affichée)</span>
|
||||
{{ dateFr(objetOuvert.date_original) }}
|
||||
<span v-if="objetOuvert.date_original_nature === 'vue'" class="cf__discret">(aucune date affichée)</span>
|
||||
</dd>
|
||||
</template>
|
||||
<template v-if="objetDe(fiche.id)!.statut">
|
||||
<template v-if="objetOuvert.statut">
|
||||
<dt>Statut</dt>
|
||||
<dd>{{ objetDe(fiche.id)!.statut }}</dd>
|
||||
<dd>{{ objetOuvert.statut }}</dd>
|
||||
</template>
|
||||
<template v-if="objetDe(fiche.id)!.url_canonique">
|
||||
<template v-if="objetOuvert.url_canonique">
|
||||
<dt>Adresse</dt>
|
||||
<dd>
|
||||
<a :href="String(objetDe(fiche.id)!.url_canonique)" target="_blank" rel="noopener noreferrer" class="cf__lien">{{ urlCourte(String(objetDe(fiche.id)!.url_canonique)) }}<span aria-hidden="true"> ↗</span><span class="cn-sr"> (nouvel onglet)</span></a>
|
||||
<a :href="String(objetOuvert.url_canonique)" target="_blank" rel="noopener noreferrer" class="cf__lien">{{ urlCourte(String(objetOuvert.url_canonique)) }}<span aria-hidden="true"> ↗</span><span class="sr-only"> (nouvel onglet)</span></a>
|
||||
</dd>
|
||||
</template>
|
||||
</dl>
|
||||
|
||||
<!-- Sources d'un concept -->
|
||||
<section v-if="sourcesDe(fiche.id).length" class="cf__bloc" :aria-labelledby="`cf-sources-${idDom(fiche.id)}`">
|
||||
<section v-if="sourcesOuvertes.length" class="cf__bloc" :aria-labelledby="`cf-sources-${idDom(fiche.id)}`">
|
||||
<h3 :id="`cf-sources-${idDom(fiche.id)}`" class="cf__soustitre">Sources</h3>
|
||||
<ul class="cf__liste">
|
||||
<li v-for="s in sourcesDe(fiche.id)" :key="s.id" class="cf__source">
|
||||
<li v-for="s in sourcesOuvertes" :key="s.id" class="cf__source">
|
||||
<button v-if="estRendu(s)" type="button" class="cf__vers" @click="vf.ouvrirFiche(s.id)">{{ s.nom_canonique }}</button>
|
||||
<span v-else>{{ s.nom_canonique }}</span>
|
||||
<span class="cf__discret">
|
||||
@@ -99,17 +99,17 @@
|
||||
<template v-if="!estRendu(s)"> · à creuser</template>
|
||||
</span>
|
||||
<a v-if="s.url_canonique" :href="String(s.url_canonique)" target="_blank" rel="noopener noreferrer" class="cf__lien cf__lien--ext">
|
||||
lien<span aria-hidden="true"> ↗</span><span class="cn-sr"> vers {{ s.nom_canonique }} (nouvel onglet)</span>
|
||||
lien<span aria-hidden="true"> ↗</span><span class="sr-only"> vers {{ s.nom_canonique }} (nouvel onglet)</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<!-- Relations typées, avec leur provenance -->
|
||||
<section v-if="relationsDe(fiche.id).length" class="cf__bloc" :aria-labelledby="`cf-rel-${idDom(fiche.id)}`">
|
||||
<section v-if="relationsOuvertes.length" class="cf__bloc" :aria-labelledby="`cf-rel-${idDom(fiche.id)}`">
|
||||
<h3 :id="`cf-rel-${idDom(fiche.id)}`" class="cf__soustitre">Relations</h3>
|
||||
<ul class="cf__liste">
|
||||
<li v-for="r in relationsDe(fiche.id)" :key="r.cle" class="cf__relation">
|
||||
<li v-for="r in relationsOuvertes" :key="r.cle" class="cf__relation">
|
||||
<span class="cf__type">{{ r.libelle }}</span>
|
||||
<button v-if="r.cible && estRendu(r.cible)" type="button" class="cf__vers" @click="vf.ouvrirFiche(r.cible.id)">{{ r.cible.nom_canonique }}</button>
|
||||
<span v-else-if="r.cible">{{ r.cible.nom_canonique }} <span class="cf__discret">(non publié)</span></span>
|
||||
@@ -118,26 +118,26 @@
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<p v-if="objetDe(fiche.id)!.registre_id" class="cf__registre">
|
||||
Renvoie au registre des œuvres : <code>{{ objetDe(fiche.id)!.registre_id }}</code>
|
||||
<p v-if="objetOuvert.registre_id" class="cf__registre">
|
||||
Renvoie au registre des œuvres : <code>{{ objetOuvert.registre_id }}</code>
|
||||
</p>
|
||||
|
||||
<!-- Crédit, licence, dettes -->
|
||||
<section class="cf__bloc cf__credit" :aria-labelledby="`cf-credit-${idDom(fiche.id)}`">
|
||||
<h3 :id="`cf-credit-${idDom(fiche.id)}`" class="cf__soustitre">Crédit et licence</h3>
|
||||
<p v-if="objetDe(fiche.id)!.credit">Crédit : {{ objetDe(fiche.id)!.credit }}</p>
|
||||
<p v-if="objetDe(fiche.id)!.nature === 'concept'">Cette fiche : {{ jeu.licence_couche }}, couche de connaissances AEP.</p>
|
||||
<p v-else-if="objetDe(fiche.id)!.licence">Licence de l’original : {{ objetDe(fiche.id)!.licence }}.</p>
|
||||
<template v-if="dettesDe(fiche.id).length">
|
||||
<p v-if="objetOuvert.credit">Crédit : {{ objetOuvert.credit }}</p>
|
||||
<p v-if="objetOuvert.nature === 'concept'">Cette fiche : {{ jeu.licence_couche }}, couche de connaissances AEP.</p>
|
||||
<p v-else-if="objetOuvert.licence">Licence de l’original : {{ objetOuvert.licence }}.</p>
|
||||
<template v-if="dettesOuvertes.length">
|
||||
<p class="cf__dettes-titre">Dettes non créditées par la source :</p>
|
||||
<ul class="cf__dettes">
|
||||
<li v-for="d in dettesDe(fiche.id)" :key="d">{{ d }}</li>
|
||||
<li v-for="d in dettesOuvertes" :key="d">{{ d }}</li>
|
||||
</ul>
|
||||
</template>
|
||||
<template v-if="vacancesDe(fiche.id).length">
|
||||
<template v-if="vacancesOuvertes.length">
|
||||
<p class="cf__dettes-titre">Ce qu’on n’a pas trouvé :</p>
|
||||
<ul class="cf__dettes">
|
||||
<li v-for="v in vacancesDe(fiche.id)" :key="v.enonce">{{ v.enonce }} <span class="cf__discret">(constaté le {{ dateFr(v.date) }})</span></li>
|
||||
<li v-for="v in vacancesOuvertes" :key="v.enonce">{{ v.enonce }} <span class="cf__discret">(constaté le {{ dateFr(v.date) }})</span></li>
|
||||
</ul>
|
||||
</template>
|
||||
</section>
|
||||
@@ -151,29 +151,27 @@
|
||||
<script setup lang="ts">
|
||||
import jeuBrut from '~/data/connaissances/fixture-lot2.json'
|
||||
import type { ConfigVueFiches } from '~/utils/vueFiches'
|
||||
import {
|
||||
fichesConnaissances, grapheConnaissances, estRendu, valeurPorteur, LIBELLES_NATURE,
|
||||
type JeuCouche, type ObjetCouche,
|
||||
} from '~/composables/useFicheAdapter'
|
||||
|
||||
type Nature = ObjetCouche['nature']
|
||||
import type { JeuConnaissances, ObjetConnaissance } from '~/utils/connaissances/valider'
|
||||
import { lecture, estRendu, sourcesDe, relationsDe, dettesDe, vacancesDe } from '~/utils/connaissances/lire'
|
||||
import { NATURES, ECHELLES, COUCHES, LIBELLES_NATURE, LIBELLES_COUCHE, type Nature } from '~/utils/connaissances/vocabulaire'
|
||||
import { fichesConnaissances, grapheConnaissances, valeurPorteur } from '~/composables/useFicheAdapter'
|
||||
|
||||
// Données au build : import statique de la fixture B18 (B20 branchera /api/connaissances).
|
||||
const jeu = jeuBrut as unknown as JeuCouche & { licence_couche: string }
|
||||
const parId = new Map(jeu.objets.map((o) => [o.id, o]))
|
||||
const objetDe = (id: string | number) => parId.get(String(id)) as (ObjetCouche & Record<string, any>) | undefined
|
||||
const jeu = jeuBrut as unknown as JeuConnaissances
|
||||
const lu = lecture(jeu)
|
||||
|
||||
const fiches = fichesConnaissances(jeu)
|
||||
const graphe = grapheConnaissances(jeu)
|
||||
const nbConcepts = jeu.objets.filter((o) => o.nature === 'concept' && estRendu(o)).length
|
||||
const nbConcepts = [...lu.rendus.values()].filter((o) => o.nature === 'concept').length
|
||||
|
||||
// ── Configuration de la vue fiches : nature, échelle, porteur, couche ──
|
||||
const NATURES: Nature[] = ['concept', 'texte', 'organisation', 'outil']
|
||||
// Ordre d'affichage des natures : les concepts d'abord (le vocabulaire les tient dans l'ordre du schéma).
|
||||
const ORDRE_NATURES: Nature[] = ['concept', ...NATURES.filter((n) => n !== 'concept')]
|
||||
const presentes = (dim: string) => new Set(fiches.flatMap((f) => f.etiquettes?.[dim] ?? []))
|
||||
const config: ConfigVueFiches = {
|
||||
dimensions: [
|
||||
{ cle: 'nature', libelle: 'Nature', variante: 'fonction', valeurs: NATURES.filter((n) => presentes('nature').has(n)).map((n) => ({ valeur: n, libelle: LIBELLES_NATURE[n] })) },
|
||||
{ cle: 'echelle', libelle: 'Échelle', variante: 'echelle', valeurs: ['S', 'M', 'XL'].filter((e) => presentes('echelle').has(e)).map((e) => ({ valeur: e, libelle: e })) },
|
||||
{ cle: 'nature', libelle: 'Nature', variante: 'fonction', valeurs: ORDRE_NATURES.filter((n) => presentes('nature').has(n)).map((n) => ({ valeur: n, libelle: LIBELLES_NATURE[n] })) },
|
||||
{ cle: 'echelle', libelle: 'Échelle', variante: 'echelle', valeurs: ECHELLES.filter((e) => presentes('echelle').has(e)).map((e) => ({ valeur: e, libelle: e })) },
|
||||
{
|
||||
cle: 'porteur',
|
||||
libelle: 'Porteur',
|
||||
@@ -182,7 +180,7 @@ const config: ConfigVueFiches = {
|
||||
.filter((o) => o.nature === 'organisation' && estRendu(o) && presentes('porteur').has(valeurPorteur(o.id)))
|
||||
.map((o) => ({ valeur: valeurPorteur(o.id), libelle: o.nom_canonique })),
|
||||
},
|
||||
{ cle: 'couche', libelle: 'Couche', variante: 'echelle', valeurs: ['socle', 'actualite'].filter((c) => presentes('couche').has(c)).map((c) => ({ valeur: c, libelle: c === 'socle' ? 'Socle' : 'Actualité' })) },
|
||||
{ cle: 'couche', libelle: 'Couche', variante: 'echelle', valeurs: COUCHES.filter((c) => presentes('couche').has(c)).map((c) => ({ valeur: c, libelle: LIBELLES_COUCHE[c] })) },
|
||||
],
|
||||
tris: ['nom', 'recent', 'pertinence'],
|
||||
triDefaut: 'nom',
|
||||
@@ -194,45 +192,12 @@ const config: ConfigVueFiches = {
|
||||
|
||||
const vf = useVueFiches(fiches, config)
|
||||
|
||||
// ── Détail ──
|
||||
const LIBELLES_RELATION: Record<string, [string, string]> = {
|
||||
extrait_de: ['extrait de', 'source de'],
|
||||
porte_par: ['porté par', 'porte'],
|
||||
republication_de: ['republication de', 'republié par'],
|
||||
meme_objet_que: ['même objet que', 'même objet que'],
|
||||
recoupe: ['recoupe', 'recoupe'],
|
||||
precise: ['précise', 'précisé par'],
|
||||
contredit: ['contredit', 'contredit par'],
|
||||
condition_de: ['condition de', 'a pour condition'],
|
||||
homonyme_de: ['homonyme de, fusion refusée :', 'homonyme de, fusion refusée :'],
|
||||
}
|
||||
|
||||
/** Sources d'un concept (extrait_de), publiées ou non : une source à creuser se dit, elle ne disparaît pas. */
|
||||
function sourcesDe(id: string | number) {
|
||||
return jeu.relations
|
||||
.filter((r) => r.type === 'extrait_de' && r.de === String(id))
|
||||
.map((r) => objetDe(r.vers))
|
||||
.filter((o): o is ObjetCouche & Record<string, any> => !!o && o.etat !== 'ecarte')
|
||||
}
|
||||
|
||||
/** Relations de l'objet, sauf ses sources (au-dessus) et le registre (une autre base, pas un nœud de la couche). */
|
||||
function relationsDe(id: string | number) {
|
||||
const i = String(id)
|
||||
const out: { cle: string; libelle: string; cible: (ObjetCouche & Record<string, any>) | undefined; provenance: string }[] = []
|
||||
jeu.relations.forEach((r, k) => {
|
||||
if (r.etat === 'ecarte' || r.type === 'renvoie_a' || !LIBELLES_RELATION[r.type]) return
|
||||
if (r.de === i && r.type === 'extrait_de') return
|
||||
const sens = r.de === i ? 0 : r.vers === i ? 1 : -1
|
||||
if (sens < 0) return
|
||||
const cible = objetDe(sens === 0 ? r.vers : r.de)
|
||||
if (!cible || cible.etat === 'ecarte') return
|
||||
out.push({ cle: `${k}`, libelle: LIBELLES_RELATION[r.type][sens], cible, provenance: r.provenance })
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
const dettesDe = (id: string | number) => (objetDe(id)?.dettes_non_creditees as string[] | undefined) ?? []
|
||||
const vacancesDe = (id: string | number) => (objetDe(id)?.vacances as { enonce: string; date: string }[] | undefined) ?? []
|
||||
// ── Détail : l'objet de la fiche ouverte, typé, lu une fois par fiche (utils/connaissances/lire.ts) ──
|
||||
const objetOuvert = computed<ObjetConnaissance | undefined>(() => (vf.ficheOuverte ? lu.rendus.get(String(vf.ficheOuverte.id)) : undefined))
|
||||
const sourcesOuvertes = computed(() => (objetOuvert.value ? sourcesDe(lu, objetOuvert.value.id) : []))
|
||||
const relationsOuvertes = computed(() => (objetOuvert.value ? relationsDe(lu, objetOuvert.value.id) : []))
|
||||
const dettesOuvertes = computed(() => dettesDe(objetOuvert.value))
|
||||
const vacancesOuvertes = computed(() => vacancesDe(objetOuvert.value))
|
||||
|
||||
const MOIS = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre']
|
||||
function dateFr(d: unknown): string {
|
||||
@@ -269,12 +234,12 @@ useSeoMeta({
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: var(--space-2xs, 0.25rem) var(--space-md);
|
||||
gap: var(--space-2xs) var(--space-md);
|
||||
padding: var(--space-xs) var(--space-md);
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
}
|
||||
.cn-tete__titre { margin: 0; font-size: 1.25rem; font-weight: var(--fw-bold); line-height: 1.25; }
|
||||
.cn-tete__titre { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: 1.25; }
|
||||
.cn-bandeau {
|
||||
flex: 1 1 32rem;
|
||||
min-width: 0;
|
||||
@@ -287,35 +252,27 @@ useSeoMeta({
|
||||
.cn-bandeau a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
|
||||
.cn-vue { flex: 1 1 0; min-height: 0; min-width: 0; }
|
||||
|
||||
.cn-sr {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ── Fiche d'un objet ── */
|
||||
.cf { min-width: 0; overflow-wrap: anywhere; }
|
||||
.cf p { margin: 0; }
|
||||
.cf__nature {
|
||||
font-size: var(--fs-xs, 0.75rem);
|
||||
font-size: var(--fs-xs);
|
||||
font-weight: var(--fw-semibold);
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: color-mix(in srgb, var(--text) 78%, transparent);
|
||||
}
|
||||
.cf__titre { margin: 2px 0 var(--space-xs); font-size: 1.25rem; font-weight: var(--fw-bold); line-height: 1.25; }
|
||||
.cf__titre { margin: 2px 0 var(--space-xs); font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: 1.25; }
|
||||
.cf__chips { margin-bottom: var(--space-sm); }
|
||||
.cf__definition { font-size: 1rem; line-height: 1.55; }
|
||||
.cf__mention { margin-top: 2px !important; font-size: var(--fs-xs, 0.75rem); color: color-mix(in srgb, var(--text) 78%, transparent); }
|
||||
.cf__definition { font-size: var(--fs-base); line-height: 1.55; }
|
||||
.cf__mention { margin-top: 2px !important; font-size: var(--fs-xs); color: color-mix(in srgb, var(--text) 78%, transparent); }
|
||||
.cf__faits { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px var(--space-sm); margin: 0; font-size: var(--fs-sm); }
|
||||
.cf__faits dt { font-weight: var(--fw-semibold); }
|
||||
.cf__faits dd { margin: 0; min-width: 0; }
|
||||
.cf__bloc { margin-top: var(--space-md); }
|
||||
.cf__soustitre { margin: 0 0 var(--space-2xs, 0.25rem); font-size: var(--fs-sm); font-weight: var(--fw-bold); }
|
||||
.cf__liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2xs, 0.25rem); font-size: var(--fs-sm); line-height: 1.45; }
|
||||
.cf__soustitre { margin: 0 0 var(--space-2xs); font-size: var(--fs-sm); font-weight: var(--fw-bold); }
|
||||
.cf__liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2xs); font-size: var(--fs-sm); line-height: 1.45; }
|
||||
.cf__vers {
|
||||
padding: var(--space-2xs) 0;
|
||||
min-height: 44px;
|
||||
@@ -339,9 +296,9 @@ useSeoMeta({
|
||||
display: inline-block;
|
||||
margin-left: 6px;
|
||||
padding: 0 6px;
|
||||
border-radius: 999px;
|
||||
border-radius: var(--radius-full);
|
||||
border: 1px solid var(--border-strong, var(--border));
|
||||
font-size: var(--fs-xs, 0.75rem);
|
||||
font-size: var(--fs-xs);
|
||||
color: color-mix(in srgb, var(--text) 82%, transparent);
|
||||
}
|
||||
.cf__provenance--curation { border-style: dashed; }
|
||||
@@ -351,8 +308,7 @@ useSeoMeta({
|
||||
.cf__dettes { margin: 2px 0 0; padding-left: 1.1rem; }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.cn-tete { padding: var(--space-2xs, 0.25rem) var(--space-sm); }
|
||||
.cn-tete__titre { font-size: 1.1rem; }
|
||||
.cn-bandeau { font-size: var(--fs-xs, 0.75rem); }
|
||||
.cn-tete { padding: var(--space-2xs) var(--space-sm); }
|
||||
.cn-bandeau { font-size: var(--fs-xs); }
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Tests de la couche de connaissances partagées (B18 M5) : schéma, validateur, fixture du
|
||||
* lot 2, jointure registre_id. Charge les VRAIS utils/connaissances/*.ts via jiti (même
|
||||
* patron que test-seo.mjs). Aucun accès réseau, aucune lecture du vault.
|
||||
* B19b M4 : vocabulaire égal au schéma, géométrie du graphe (graphe.ts), lecture d’une fiche (lire.ts).
|
||||
* Usage : node scripts/test-connaissances.mjs
|
||||
*/
|
||||
|
||||
@@ -101,7 +102,7 @@ for (const [type, de, vers, prov] of TABLE) {
|
||||
// Rien de copié : définitions dans nos mots, rien du vault
|
||||
for (const c of fixture.objets.filter((o) => o.nature === 'concept')) {
|
||||
const k = V.plusLongueSuiteCommune(c.definition_courte, c.libelle_source)
|
||||
ok(k <= 12, `${c.id} : aucune suite de plus de douze mots commune avec libelle_source (${k})`)
|
||||
ok(k <= V.MOTS_COPIE_MAX, `${c.id} : aucune suite de plus de ${V.MOTS_COPIE_MAX} mots commune avec libelle_source (${k})`)
|
||||
}
|
||||
const texte = JSON.stringify(fixture)
|
||||
ok(!/\[\[|Dropbox|IPCJRA|\.md\b|1 PROJETS|2 CASQUETTES/.test(texte), 'fixture : aucune note ni chemin du vault')
|
||||
@@ -201,10 +202,100 @@ const A = await jiti.import(join(racine, 'composables', 'useFicheAdapter.ts'))
|
||||
ok(!g.liens.some((l) => l.type === 'renvoie_a' || l.type === 'homonyme_de'), 'graphe : ni renvoie_a ni homonyme vers un non-publié')
|
||||
ok(g.noeuds.every((x) => !('x' in x) && !('y' in x)), 'graphe : aucune position dans les données')
|
||||
// Le croisement architectures invisibles ↔ matrice (curation, Jules 08/10) devient un lien du graphe dès que cpt:matrice-aep est publié ; a_trier le 27/10 : le lien attend.
|
||||
const matriceRendue = A.estRendu(objet(fixture, 'cpt:matrice-aep'))
|
||||
const matriceRendue = objet(fixture, 'cpt:matrice-aep').etat === 'publie'
|
||||
ok(g.liens.some((l) => l.type === 'recoupe' && l.de === 'cpt:architectures-invisibles' && l.vers === 'cpt:matrice-aep') === matriceRendue, `graphe : le croisement architectures invisibles ↔ matrice est un lien si et seulement si la matrice est rendue (${matriceRendue})`)
|
||||
ok(g.liens.some((l) => l.type === 'condition_de' && l.de === 'cpt:holoptisme' && l.vers === 'cpt:economie-du-don'), 'graphe : holoptisme → économie du don (source) est un lien')
|
||||
}
|
||||
|
||||
// ── B19b M4 : le vocabulaire, écrit une fois, égal au schéma ────
|
||||
const W = await jiti.import(join(racine, 'utils', 'connaissances', 'vocabulaire.ts'))
|
||||
const trieCles = (o) => Object.fromEntries(Object.keys(o).sort().map((k) => [k, o[k]]))
|
||||
{
|
||||
const memes = (a, b) => JSON.stringify([...a]) === JSON.stringify([...b])
|
||||
ok(memes(W.NATURES, D.objet.properties.nature.enum), 'vocabulaire : natures = schéma', JSON.stringify(W.NATURES))
|
||||
ok(memes(W.ECHELLES, D.objet.properties.echelles.items.enum), 'vocabulaire : échelles = schéma', JSON.stringify(W.ECHELLES))
|
||||
ok(memes(W.COUCHES, D.objet.properties.couche.enum), 'vocabulaire : couches = schéma', JSON.stringify(W.COUCHES))
|
||||
ok(memes(W.ETATS, D.etat.enum) && W.ETATS.includes(W.ETAT_RENDU), 'vocabulaire : états = schéma, l’état rendu en fait partie', JSON.stringify(W.ETATS))
|
||||
// Préfixes : le motif d'identifiant du schéma, et le `allOf` nature → ^préfixe:
|
||||
const duMotif = D.id.pattern.match(/^\^\(([^)]+)\)/)[1].split('|')
|
||||
const duAllOf = Object.fromEntries(D.objet.allOf.map((r) => [r.if.properties.nature.const, r.then.properties.id.pattern.replace(/^\^/, '').replace(/:$/, '')]))
|
||||
ok(memes(Object.values(W.PREFIXES).sort(), [...duMotif].sort()), 'vocabulaire : préfixes = motif d’identifiant du schéma', duMotif.join(','))
|
||||
ok(JSON.stringify(trieCles(W.PREFIXES)) === JSON.stringify(trieCles(duAllOf)), 'vocabulaire : préfixe de chaque nature = allOf du schéma', JSON.stringify(duAllOf))
|
||||
ok(W.NATURES.every((x) => W.LIBELLES_NATURE[x]) && W.COUCHES.every((c) => W.LIBELLES_COUCHE[c]), 'vocabulaire : un libellé par nature et par couche')
|
||||
ok(V.MOTS_COPIE_MAX === W.MOTS_COPIE_MAX && V.PREFIXES === W.PREFIXES && V.NATURES === W.NATURES, 'vocabulaire : le validateur réexporte le même vocabulaire (aucune recopie)')
|
||||
ok(W.RE_PREFIXE.test('cpt:x') && W.RE_PREFIXE.test('org:aep') && !W.RE_PREFIXE.test('registre:x'), 'vocabulaire : motif de préfixe (cpt:, org: oui ; registre: non)')
|
||||
}
|
||||
|
||||
// ── B19b M4 : géométrie du graphe (utils/connaissances/graphe.ts) ──
|
||||
const G = await jiti.import(join(racine, 'utils', 'connaissances', 'graphe.ts'))
|
||||
{
|
||||
const { noeuds, liens } = A.grapheConnaissances(fixture)
|
||||
const prin = new Set(['concept'])
|
||||
const p1 = G.disposer(noeuds, liens, prin)
|
||||
const p2 = G.disposer(copie(noeuds), copie(liens), prin)
|
||||
const plat = (p) => JSON.stringify([...p].map(([id, { x, y }]) => [id, x, y]))
|
||||
ok(p1.size === noeuds.length && plat(p1) === plat(p2), `graphe : graine fixe, deux calculs = mêmes positions (${p1.size} nœuds)`)
|
||||
const b = G.boite(p1.values())
|
||||
ok(Math.abs(Math.max(b.x1 - b.x0, b.y1 - b.y0) - 1) < 1e-9 && Math.abs(b.x0 + b.x1) < 1e-9 && Math.abs(b.y0 + b.y1) < 1e-9, 'graphe : dessin centré, d’étendue 1', JSON.stringify(b))
|
||||
ok([...p1.values()].every((p) => Number.isFinite(p.x) && Number.isFinite(p.y)), 'graphe : aucune position infinie ou NaN')
|
||||
ok(G.disposerEnCache(noeuds, liens, prin) === G.disposerEnCache(copie(noeuds), copie(liens), prin), 'graphe : cache par signature (même graphe, même objet rendu)')
|
||||
ok(plat(G.disposerEnCache(noeuds, liens, prin)) === plat(p1), 'graphe : le cache rend les positions de disposer')
|
||||
ok(G.disposer([], [], prin).size === 0 && !Number.isFinite(G.boite([]).x0), 'graphe : graphe vide → aucune position ; boîte vide → bornes infinies')
|
||||
const L = [
|
||||
{ de: 'a', vers: 'b', type: 't', provenance: 'source' },
|
||||
{ de: 'b', vers: 'c', type: 't', provenance: 'source' },
|
||||
{ de: 'd', vers: 'c', type: 't', provenance: 'curation' },
|
||||
]
|
||||
const tri = (s) => [...s].sort().join(',')
|
||||
ok(tri(G.voisinage(L, 'a', 1)) === 'a,b', 'voisinage : un pas (le nœud compris)')
|
||||
ok(tri(G.voisinage(L, 'a', 2)) === 'a,b,c', 'voisinage : deux pas')
|
||||
ok(tri(G.voisinage(L, 'c', 1)) === 'b,c,d', 'voisinage : les liens se suivent dans les deux sens')
|
||||
ok(G.voisinage(L, 'a', 'tout') === null, 'voisinage : « tout » = null (tout le graphe)')
|
||||
ok(tri(G.voisinage(L, 'z', 2)) === 'z', 'voisinage : nœud isolé → lui seul')
|
||||
ok(tri(G.voisinage(liens, 'cpt:holoptisme', 1)) === tri(['cpt:holoptisme', 'txt:hs-holo-sapiens-fr', 'txt:hs-economie-du-don', 'cpt:economie-du-don', 'cpt:quatre-formes-ic']), 'voisinage : holoptisme à un pas = ses deux sources et ses deux concepts liés', tri(G.voisinage(liens, 'cpt:holoptisme', 1)))
|
||||
}
|
||||
|
||||
// ── B19b M4 : lecture d'une fiche (utils/connaissances/lire.ts) ──
|
||||
const R = await jiti.import(join(racine, 'utils', 'connaissances', 'lire.ts'))
|
||||
{
|
||||
const l = R.lecture(fixture)
|
||||
ok(R.lecture(fixture) === l, 'lecture : l’index est construit une fois par jeu (mémorisé)')
|
||||
ok(l.rendus.size === fixture.objets.filter((o) => o.etat === 'publie').length && [...l.rendus.values()].every(R.estRendu), 'lecture : rendus = objets publiés')
|
||||
const ids = (xs) => xs.map((x) => x.id).sort().join(',')
|
||||
ok(ids(R.sourcesDe(l, 'cpt:holoptisme')) === 'txt:hs-economie-du-don,txt:hs-holo-sapiens-fr', 'sourcesDe : les deux sources d’holoptisme', ids(R.sourcesDe(l, 'cpt:holoptisme')))
|
||||
ok(R.sourcesDe(l, 'cpt:economie-du-don').some((s) => s.etat === 'a_creuser'), 'sourcesDe : une source à creuser se dit (elle ne disparaît pas)')
|
||||
{
|
||||
const j = copie(fixture)
|
||||
objet(j, 'txt:hs-economie-du-don').etat = 'ecarte'
|
||||
ok(ids(R.sourcesDe(R.lecture(j), 'cpt:holoptisme')) === 'txt:hs-holo-sapiens-fr', 'sourcesDe : une source écartée n’est pas dite')
|
||||
}
|
||||
const rel = (id) => R.relationsDe(l, id).map((r) => `${r.libelle}>${r.cible.id}>${r.provenance}`)
|
||||
const h = rel('cpt:holoptisme')
|
||||
ok(h.includes('condition de>cpt:economie-du-don>source') && h.includes('précise>cpt:quatre-formes-ic>curation'), 'relationsDe : sens direct, libellé et provenance', h.join(' | '))
|
||||
ok(!h.some((x) => x.startsWith('extrait de')), 'relationsDe : les sources restent dans sourcesDe (pas en double)')
|
||||
ok(rel('cpt:economie-du-don').includes('a pour condition>cpt:holoptisme>source'), 'relationsDe : sens inverse (libellé de l’autre bout)', rel('cpt:economie-du-don').join(' | '))
|
||||
ok(rel('txt:hs-holo-sapiens-fr').includes('source de>cpt:holoptisme>source'), 'relationsDe : un texte dit de quels concepts il est la source', rel('txt:hs-holo-sapiens-fr').join(' | '))
|
||||
ok(rel('cpt:signaux-faibles-noubel').some((x) => x.startsWith('homonyme de, fusion refusée :>cpt:signaux-faibles-ansoff')), 'relationsDe : homonyme_de libellé « fusion refusée »', rel('cpt:signaux-faibles-noubel').join(' | '))
|
||||
{
|
||||
const j = copie(fixture)
|
||||
j.relations.find((r) => r.type === 'precise' && r.de === 'cpt:holoptisme').etat = 'ecarte'
|
||||
j.relations.push({ type: 'renvoie_a', de: 'cpt:holoptisme', vers: 'registre:P2-18', provenance: 'curation', etat: 'publie' })
|
||||
const r = R.relationsDe(R.lecture(j), 'cpt:holoptisme')
|
||||
ok(!r.some((x) => x.type === 'precise'), 'relationsDe : une relation écartée est ignorée')
|
||||
ok(!r.some((x) => x.type === 'renvoie_a'), 'relationsDe : renvoie_a exclu (le registre, une autre base)')
|
||||
}
|
||||
{
|
||||
const g = R.relationsParLibelle(l, 'cpt:quatre-formes-ic')
|
||||
ok(g.length > 0 && g.every((x) => x.relations.every((r) => r.libelle === x.libelle)) && new Set(g.map((x) => x.libelle)).size === g.length, 'relationsParLibelle : une ligne par libellé', g.map((x) => `${x.libelle}(${x.relations.length})`).join(' '))
|
||||
}
|
||||
ok(R.dettesDe(objet(fixture, 'cpt:holoptisme')).length === 1 && R.dettesDe(undefined).length === 0, 'dettesDe : celles de l’objet ; aucun objet → aucune')
|
||||
{
|
||||
const avecVacance = fixture.objets.find((o) => (o.vacances ?? []).length)
|
||||
ok(!!avecVacance && R.vacancesDe(avecVacance).length === avecVacance.vacances.length && R.vacancesDe(undefined).length === 0, `vacancesDe : celles de l’objet (${avecVacance?.id}) ; aucun objet → aucune`)
|
||||
}
|
||||
ok(R.porteursDe(l, objet(fixture, 'cpt:holoptisme')).map((p) => p.id).join() === 'org:holosapiens' && R.porteursDe(l, objet(fixture, 'org:holosapiens'))[0].id === 'org:holosapiens', 'porteursDe : l’organisation rendue ; une organisation se porte elle-même')
|
||||
ok(Object.keys(R.LIBELLES_RELATION).every((t) => D.relation.properties.type.enum.includes(t)) && !('renvoie_a' in R.LIBELLES_RELATION), 'LIBELLES_RELATION : des types du schéma, sans renvoie_a')
|
||||
}
|
||||
|
||||
console.log(`\n${n - echecs}/${n} OK${echecs ? ` · ${echecs} ÉCHEC(S)` : ''}`)
|
||||
process.exit(echecs ? 1 : 0)
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* graphe — B19b M4. La géométrie de `GrapheConnaissances`, sortie du `.vue` (DESIGN-SYSTEM
|
||||
* §Vue fiches : la logique pure vit dans `utils/`) et testée par
|
||||
* `scripts/test-connaissances.mjs`. Fonctions pures, mêmes signatures qu'en B19 ; aucune
|
||||
* connaissance de la couche, de la vue fiches ni du DOM : B9 réécrit les reprend telles quelles.
|
||||
*
|
||||
* - `disposer` : force simple à graine fixe, positions dans un repère sans unité, centré,
|
||||
* d'étendue 1 (aucune position en données) ;
|
||||
* - `disposerEnCache` : la même, mémorisée par signature du graphe (une fois par processus) ;
|
||||
* - `voisinage` : identifiants à `pas` liens au plus d'un nœud (graphe local d'Obsidian) ;
|
||||
* - `boite` : boîte englobante d'un ensemble de points, une seule écriture pour le dessin et la caméra.
|
||||
*/
|
||||
|
||||
/** Un nœud : `kind` dit sa forme (principal si dans `kindsPrincipaux`, sinon secondaire). */
|
||||
export interface NoeudGraphe { id: string; libelle: string; kind: string; poids?: number }
|
||||
export interface LienGraphe { de: string; vers: string; type: string; provenance: string }
|
||||
export type Pas = 1 | 2 | 'tout'
|
||||
export type Pt = { x: number; y: number }
|
||||
export interface Boite { x0: number; x1: number; y0: number; y1: number }
|
||||
|
||||
/** Boîte englobante ; vide = bornes infinies (`Number.isFinite(b.x0)` est faux). */
|
||||
export function boite(points: Iterable<Pt>): Boite {
|
||||
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
|
||||
for (const p of points) { x0 = Math.min(x0, p.x); x1 = Math.max(x1, p.x); y0 = Math.min(y0, p.y); y1 = Math.max(y1, p.y) }
|
||||
return { x0, x1, y0, y1 }
|
||||
}
|
||||
|
||||
/** PRNG à graine fixe (mulberry32) : même graphe, même dessin, au serveur comme au navigateur. */
|
||||
function alea(graine: number) {
|
||||
let a = graine >>> 0
|
||||
return () => {
|
||||
a = (a + 0x6d2b79f5) >>> 0
|
||||
let t = a
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1)
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force simple (Fruchterman-Reingold), graine fixe, nombre de pas fixe : positions dans un
|
||||
* repère sans unité, centré, d'étendue 1. Fonction pure de (nœuds, liens, principaux).
|
||||
*/
|
||||
export function disposer(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
|
||||
const n = noeuds.length
|
||||
const pos = new Map<string, Pt>()
|
||||
if (!n) return pos
|
||||
const rnd = alea(0x9e3779b9)
|
||||
const index = new Map(noeuds.map((x, i) => [x.id, i]))
|
||||
const aretes = liens
|
||||
.map((l) => [index.get(l.de), index.get(l.vers)] as const)
|
||||
.filter((a): a is readonly [number, number] => a[0] != null && a[1] != null && a[0] !== a[1])
|
||||
const voisins: number[][] = noeuds.map(() => [])
|
||||
for (const [a, b] of aretes) { voisins[a].push(b); voisins[b].push(a) }
|
||||
|
||||
// Départ : les principaux en cercle, chaque secondaire au barycentre de ses voisins principaux.
|
||||
const prin = noeuds.map((x, i) => (principaux.has(x.kind) ? i : -1)).filter((i) => i >= 0)
|
||||
const X = new Float64Array(n)
|
||||
const Y = new Float64Array(n)
|
||||
prin.forEach((i, k) => {
|
||||
const t = (2 * Math.PI * k) / Math.max(prin.length, 1)
|
||||
X[i] = 0.4 * Math.cos(t)
|
||||
Y[i] = 0.4 * Math.sin(t)
|
||||
})
|
||||
noeuds.forEach((x, i) => {
|
||||
if (principaux.has(x.kind)) return
|
||||
const v = voisins[i].filter((j) => principaux.has(noeuds[j].kind))
|
||||
if (v.length) {
|
||||
X[i] = (v.reduce((s, j) => s + X[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
|
||||
Y[i] = (v.reduce((s, j) => s + Y[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
|
||||
} else {
|
||||
X[i] = (rnd() - 0.5) * 0.9
|
||||
Y[i] = (rnd() - 0.5) * 0.9
|
||||
}
|
||||
})
|
||||
|
||||
const k = 0.9 * Math.sqrt(1 / n)
|
||||
const ITER = 350
|
||||
const dx = new Float64Array(n)
|
||||
const dy = new Float64Array(n)
|
||||
for (let it = 0; it < ITER; it++) {
|
||||
const temp = 0.08 * (1 - it / ITER) + 0.002
|
||||
dx.fill(0)
|
||||
dy.fill(0)
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let j = i + 1; j < n; j++) {
|
||||
let ex = X[i] - X[j]
|
||||
let ey = Y[i] - Y[j]
|
||||
let d = Math.hypot(ex, ey)
|
||||
if (d < 1e-4) { ex = (rnd() - 0.5) * 1e-3; ey = (rnd() - 0.5) * 1e-3; d = Math.hypot(ex, ey) }
|
||||
const f = (k * k) / d
|
||||
dx[i] += (ex / d) * f; dy[i] += (ey / d) * f
|
||||
dx[j] -= (ex / d) * f; dy[j] -= (ey / d) * f
|
||||
}
|
||||
}
|
||||
for (const [a, b] of aretes) {
|
||||
const ex = X[a] - X[b]
|
||||
const ey = Y[a] - Y[b]
|
||||
const d = Math.max(Math.hypot(ex, ey), 1e-4)
|
||||
const f = (d * d) / k
|
||||
dx[a] -= (ex / d) * f; dy[a] -= (ey / d) * f
|
||||
dx[b] += (ex / d) * f; dy[b] += (ey / d) * f
|
||||
}
|
||||
for (let i = 0; i < n; i++) {
|
||||
dx[i] -= X[i] * 0.9 * k * 4
|
||||
dy[i] -= Y[i] * 0.9 * k * 4
|
||||
const d = Math.hypot(dx[i], dy[i])
|
||||
if (d > 0) {
|
||||
const m = Math.min(d, temp)
|
||||
X[i] += (dx[i] / d) * m
|
||||
Y[i] += (dy[i] / d) * m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Centré, étendue 1 (le plus grand côté de la boîte englobante)
|
||||
const { x0, x1, y0, y1 } = boite(Array.from(X, (x, i) => ({ x, y: Y[i] })))
|
||||
const e = Math.max(x1 - x0, y1 - y0) || 1
|
||||
noeuds.forEach((x, i) => pos.set(x.id, { x: (X[i] - (x0 + x1) / 2) / e, y: (Y[i] - (y0 + y1) / 2) / e }))
|
||||
return pos
|
||||
}
|
||||
|
||||
/** Cache par signature du graphe : au serveur, une fois par processus, pas une fois par requête. */
|
||||
const CACHE = new Map<string, Map<string, Pt>>()
|
||||
export function disposerEnCache(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
|
||||
const sig = JSON.stringify([noeuds.map((x) => [x.id, x.kind]), liens.map((l) => [l.de, l.vers]), [...principaux]])
|
||||
let p = CACHE.get(sig)
|
||||
if (!p) {
|
||||
p = disposer(noeuds, liens, principaux)
|
||||
if (CACHE.size > 24) CACHE.delete(CACHE.keys().next().value as string)
|
||||
CACHE.set(sig, p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
/** Identifiants à `pas` liens au plus de `id` (le nœud compris) ; `tout` = tous. */
|
||||
export function voisinage(liens: LienGraphe[], id: string, pas: Pas): Set<string> | null {
|
||||
if (pas === 'tout') return null
|
||||
const adj = new Map<string, string[]>()
|
||||
for (const l of liens) {
|
||||
if (!adj.has(l.de)) adj.set(l.de, [])
|
||||
if (!adj.has(l.vers)) adj.set(l.vers, [])
|
||||
adj.get(l.de)!.push(l.vers)
|
||||
adj.get(l.vers)!.push(l.de)
|
||||
}
|
||||
const vus = new Set([id])
|
||||
let front = [id]
|
||||
for (let p = 0; p < pas; p++) {
|
||||
const suite: string[] = []
|
||||
for (const x of front) for (const y of adj.get(x) ?? []) if (!vus.has(y)) { vus.add(y); suite.push(y) }
|
||||
front = suite
|
||||
}
|
||||
return vus
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* lire — B19b M4. Ce que la fiche d'un objet lit dans le jeu : ses sources, ses porteurs, ses
|
||||
* relations typées (dans les deux sens), ses dettes et ses vacances. Sorti de
|
||||
* `pages/connaissances.vue` et testé par `scripts/test-connaissances.mjs` ; B9 réécrit et
|
||||
* l'option B (fiches Markdown) le reprendront tel quel : il ne connaît que le jeu.
|
||||
*
|
||||
* `lecture(jeu)` indexe le jeu une fois (objets par identifiant, objets rendus) ; chaque
|
||||
* fonction prend cette lecture et un identifiant. Fonctions pures : le jeu n'est pas modifié.
|
||||
*/
|
||||
import type { JeuConnaissances, ObjetConnaissance, VacanceConnaissance } from './valider'
|
||||
import { ETAT_RENDU } from './vocabulaire'
|
||||
|
||||
/**
|
||||
* Libellé d'un type de relation, [de → vers, vers → de]. `renvoie_a` n'y est pas : il vise le
|
||||
* registre des œuvres, une autre base (rendu à part, par `registre_id`).
|
||||
*/
|
||||
export const LIBELLES_RELATION: Record<string, [string, string]> = {
|
||||
extrait_de: ['extrait de', 'source de'],
|
||||
porte_par: ['porté par', 'porte'],
|
||||
republication_de: ['republication de', 'republié par'],
|
||||
meme_objet_que: ['même objet que', 'même objet que'],
|
||||
recoupe: ['recoupe', 'recoupe'],
|
||||
precise: ['précise', 'précisé par'],
|
||||
contredit: ['contredit', 'contredit par'],
|
||||
condition_de: ['condition de', 'a pour condition'],
|
||||
homonyme_de: ['homonyme de, fusion refusée :', 'homonyme de, fusion refusée :'],
|
||||
}
|
||||
|
||||
/**
|
||||
* Ce que la page rend : les objets publiés. Un objet écarté reste en base et n'est jamais
|
||||
* rendu ; `en_file`, `a_trier` et `a_creuser` non plus, tant qu'un humain n'a pas tranché
|
||||
* (interdit n° 2 de la CONCEPTION §5).
|
||||
*/
|
||||
export const estRendu = (o: { etat: string }) => o.etat === ETAT_RENDU
|
||||
|
||||
export interface Lecture {
|
||||
jeu: JeuConnaissances
|
||||
parId: Map<string, ObjetConnaissance>
|
||||
rendus: Map<string, ObjetConnaissance>
|
||||
}
|
||||
|
||||
const LECTURES = new WeakMap<JeuConnaissances, Lecture>()
|
||||
|
||||
/** L'index d'un jeu, construit une fois par jeu (mémorisé) : la page et l'adaptateur le partagent. */
|
||||
export function lecture(jeu: JeuConnaissances): Lecture {
|
||||
let l = LECTURES.get(jeu)
|
||||
if (!l) {
|
||||
l = {
|
||||
jeu,
|
||||
parId: new Map(jeu.objets.map((o) => [o.id, o])),
|
||||
rendus: new Map(jeu.objets.filter(estRendu).map((o) => [o.id, o])),
|
||||
}
|
||||
LECTURES.set(jeu, l)
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
/** Sources d'un objet (`extrait_de`), publiées ou non : une source à creuser se dit, elle ne disparaît pas. Les écartées, non. */
|
||||
export function sourcesDe(l: Lecture, id: string): ObjetConnaissance[] {
|
||||
return l.jeu.relations
|
||||
.filter((r) => r.type === 'extrait_de' && r.de === id && r.etat !== 'ecarte')
|
||||
.map((r) => l.parId.get(r.vers))
|
||||
.filter((o): o is ObjetConnaissance => !!o && o.etat !== 'ecarte')
|
||||
}
|
||||
|
||||
/** Porteurs d'un objet : ses `porteur_ids` qui sont des organisations rendues ; une organisation se porte elle-même. */
|
||||
export function porteursDe(l: Lecture, o: ObjetConnaissance): ObjetConnaissance[] {
|
||||
if (o.nature === 'organisation') return [o]
|
||||
return (o.porteur_ids ?? []).map((id) => l.rendus.get(id)).filter((p): p is ObjetConnaissance => !!p && p.nature === 'organisation')
|
||||
}
|
||||
|
||||
export interface RelationLue {
|
||||
/** Clé stable (rang de la relation dans le jeu). */
|
||||
cle: string
|
||||
type: string
|
||||
/** 0 = l'objet est à l'origine (`de`), 1 = à l'arrivée (`vers`). */
|
||||
sens: 0 | 1
|
||||
libelle: string
|
||||
cible: ObjetConnaissance
|
||||
provenance: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Relations de l'objet, dans les deux sens, sauf ses sources (`sourcesDe`), `renvoie_a` (le
|
||||
* registre, une autre base), les relations écartées et celles vers un objet écarté.
|
||||
*/
|
||||
export function relationsDe(l: Lecture, id: string): RelationLue[] {
|
||||
const out: RelationLue[] = []
|
||||
l.jeu.relations.forEach((r, k) => {
|
||||
if (r.etat === 'ecarte' || r.type === 'renvoie_a' || !LIBELLES_RELATION[r.type]) return
|
||||
if (r.de === id && r.type === 'extrait_de') return
|
||||
if (r.de !== id && r.vers !== id) return
|
||||
const sens: 0 | 1 = r.de === id ? 0 : 1
|
||||
const cible = l.parId.get(sens === 0 ? r.vers : r.de)
|
||||
if (!cible || cible.etat === 'ecarte') return
|
||||
out.push({ cle: `${k}`, type: r.type, sens, libelle: LIBELLES_RELATION[r.type][sens], cible, provenance: r.provenance })
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
/** Les relations regroupées par libellé (un type dans un sens), dans l'ordre de première apparition : une ligne de l'en-tête chacune. */
|
||||
export function relationsParLibelle(l: Lecture, id: string): { libelle: string; relations: RelationLue[] }[] {
|
||||
const groupes = new Map<string, RelationLue[]>()
|
||||
for (const r of relationsDe(l, id)) {
|
||||
const g = groupes.get(r.libelle)
|
||||
if (g) g.push(r)
|
||||
else groupes.set(r.libelle, [r])
|
||||
}
|
||||
return [...groupes].map(([libelle, relations]) => ({ libelle, relations }))
|
||||
}
|
||||
|
||||
export const dettesDe = (o: ObjetConnaissance | undefined): string[] => o?.dettes_non_creditees ?? []
|
||||
export const vacancesDe = (o: ObjetConnaissance | undefined): VacanceConnaissance[] => o?.vacances ?? []
|
||||
@@ -8,16 +8,28 @@
|
||||
* `valider(jeu) → { ok, erreurs[] }`. Chaque erreur nomme l'identifiant en cause et la
|
||||
* règle (`R7`, `R10`, `extrait_de`, `homonyme_de`, `rendu`, `prefixe`, `orpheline`…).
|
||||
* Testé par scripts/test-connaissances.mjs. B20 l'appellera avant toute écriture.
|
||||
*
|
||||
* B19b : natures, échelles, couches, préfixes, états et seuil de copie viennent de
|
||||
* `vocabulaire.ts` (écrits une fois, comparés au schéma par le test) ; les types
|
||||
* `ObjetConnaissance` / `JeuConnaissances` sont les seuls de la couche (l'adaptateur et la
|
||||
* page les importent).
|
||||
*/
|
||||
import schema from '../../data/connaissances/schema.json'
|
||||
import {
|
||||
NATURES, ETATS, ECHELLES, COUCHES, PREFIXES, MOTS_COPIE_MAX,
|
||||
type Nature, type Echelle, type Couche,
|
||||
} from './vocabulaire'
|
||||
|
||||
// ── Vocabulaire, lu dans le schéma ─────────────────────────────────────────
|
||||
export { NATURES, ETATS, PREFIXES, MOTS_COPIE_MAX }
|
||||
|
||||
// ── Vocabulaire propre au validateur, lu dans le schéma ────────────────────
|
||||
|
||||
const DEFS = (schema as any).$defs
|
||||
const enumDe = (p: any): string[] => p?.enum ?? DEFS[(p?.$ref ?? '').replace('#/$defs/', '')]?.enum ?? []
|
||||
/** Une valeur reçue (non sûre) est-elle dans une liste du vocabulaire ? */
|
||||
const dans = (liste: readonly string[], v: unknown) => typeof v === 'string' && liste.includes(v)
|
||||
const PREFIXE_DE = PREFIXES as Record<string, string>
|
||||
|
||||
export const NATURES: string[] = DEFS.objet.properties.nature.enum
|
||||
export const ETATS: string[] = DEFS.etat.enum
|
||||
export const TYPES_RELATION: string[] = DEFS.relation.properties.type.enum
|
||||
export const PROVENANCES: string[] = DEFS.relation.properties.provenance.enum
|
||||
export const CHAMPS_OBJET = new Set(Object.keys(DEFS.objet.properties))
|
||||
@@ -26,15 +38,10 @@ const CHAMPS_FUSION = new Set(Object.keys(DEFS.fusion.properties))
|
||||
const CHAMPS_JEU = new Set(Object.keys((schema as any).properties))
|
||||
const CHAMPS_VACANCE = new Set(Object.keys(DEFS.vacance.properties))
|
||||
const METHODES = enumDe(DEFS.vacance.properties.methode)
|
||||
const ECHELLES: string[] = DEFS.objet.properties.echelles.items.enum
|
||||
const COUCHES: string[] = DEFS.objet.properties.couche.enum
|
||||
const RE_ID = new RegExp(DEFS.id.pattern)
|
||||
const RE_DATE = new RegExp(DEFS.date.pattern)
|
||||
const RE_REGISTRE = new RegExp(DEFS.refRegistre.pattern)
|
||||
|
||||
/** Préfixe d'identifiant de chaque nature. */
|
||||
export const PREFIXES: Record<string, string> = { texte: 'txt', organisation: 'org', outil: 'out', concept: 'cpt' }
|
||||
|
||||
/**
|
||||
* Champs de rendu : la structure ne se fonde pas sur le rendu (U, O §D3). Le layout est une
|
||||
* projection calculée ; une position, une couleur ou un regroupement en base est refusé.
|
||||
@@ -49,16 +56,34 @@ const RENDU = new Set(CHAMPS_RENDU)
|
||||
/** Relations entre concepts (vocabulaire « Croisement »). */
|
||||
export const CROISEMENTS = ['recoupe', 'precise', 'contredit', 'condition_de']
|
||||
|
||||
/** Longueur au-delà de laquelle une suite de mots commune à la définition et à la source est une copie. */
|
||||
export const MOTS_COPIE_MAX = 12
|
||||
// ── Types (les seuls de la couche : adaptateur, lecture et page les importent) ──
|
||||
|
||||
// ── Types ──────────────────────────────────────────────────────────────────
|
||||
export interface VacanceConnaissance { enonce: string; date: string; methode: string; perimetre?: string }
|
||||
|
||||
/**
|
||||
* Un objet de la couche. Les champs que le rendu lit sont typés ; les autres restent
|
||||
* ouverts (le validateur reçoit des données non sûres, c'est lui qui les contrôle).
|
||||
*/
|
||||
export interface ObjetConnaissance {
|
||||
id: string
|
||||
nature: 'texte' | 'organisation' | 'outil' | 'concept'
|
||||
nature: Nature
|
||||
nom_canonique: string
|
||||
etat: string
|
||||
definition_courte?: string
|
||||
libelle_source?: string
|
||||
variantes?: string[]
|
||||
porteur_ids?: string[]
|
||||
echelles?: Echelle[]
|
||||
couche?: Couche
|
||||
url_canonique?: string | null
|
||||
statut?: string
|
||||
date_original?: string | null
|
||||
date_original_nature?: 'affichee' | 'vue'
|
||||
licence?: string | null
|
||||
credit?: string | null
|
||||
dettes_non_creditees?: string[]
|
||||
vacances?: VacanceConnaissance[]
|
||||
registre_id?: string | null
|
||||
[champ: string]: any
|
||||
}
|
||||
|
||||
@@ -167,14 +192,14 @@ export function valider(jeu: JeuConnaissances): { ok: boolean; erreurs: ErreurVa
|
||||
// Identifiant : préfixe de nature, et le bon
|
||||
if (!RE_ID.test(id)) {
|
||||
err(id, 'prefixe', 'identifiant sans préfixe de nature (txt:, org:, out:, cpt:) ou mal formé')
|
||||
} else if (PREFIXES[o.nature] && !id.startsWith(`${PREFIXES[o.nature]}:`)) {
|
||||
err(id, 'prefixe', `nature « ${o.nature} » : l’identifiant doit commencer par ${PREFIXES[o.nature]}:`)
|
||||
} else if (PREFIXE_DE[o.nature] && !id.startsWith(`${PREFIXE_DE[o.nature]}:`)) {
|
||||
err(id, 'prefixe', `nature « ${o.nature} » : l’identifiant doit commencer par ${PREFIXE_DE[o.nature]}:`)
|
||||
}
|
||||
if (!NATURES.includes(o.nature)) err(id, 'schema', `nature inconnue « ${o.nature} »`)
|
||||
if (!dans(NATURES, o.nature)) err(id, 'schema', `nature inconnue « ${o.nature} »`)
|
||||
if (!o.nom_canonique) err(id, 'schema', 'nom_canonique manquant')
|
||||
if (!ETATS.includes(o.etat)) err(id, 'schema', `etat inconnu « ${o.etat} »`)
|
||||
for (const e of o.echelles ?? []) if (!ECHELLES.includes(e)) err(id, 'schema', `échelle inconnue « ${e} »`)
|
||||
if (o.couche != null && !COUCHES.includes(o.couche)) err(id, 'schema', `couche inconnue « ${o.couche} »`)
|
||||
if (!dans(ETATS, o.etat)) err(id, 'schema', `etat inconnu « ${o.etat} »`)
|
||||
for (const e of o.echelles ?? []) if (!dans(ECHELLES, e)) err(id, 'schema', `échelle inconnue « ${e} »`)
|
||||
if (o.couche != null && !dans(COUCHES, o.couche)) err(id, 'schema', `couche inconnue « ${o.couche} »`)
|
||||
for (const champ of ['date_original', 'date_republication', 'derniere_publication', 'peremption_connue', 'verdict_le', 'revu_le']) {
|
||||
if (o[champ] != null && !RE_DATE.test(String(o[champ]))) err(id, 'schema', `${champ} n’est pas une date ISO`)
|
||||
}
|
||||
@@ -214,7 +239,7 @@ export function valider(jeu: JeuConnaissances): { ok: boolean; erreurs: ErreurVa
|
||||
}
|
||||
if (!TYPES_RELATION.includes(r.type)) { err(id, 'schema', `type de relation inconnu « ${r.type} »`); continue }
|
||||
if (!PROVENANCES.includes(r.provenance)) err(id, r.type, `provenance « ${r.provenance} » : source ou curation`)
|
||||
if (!ETATS.includes(r.etat)) err(id, r.type, `etat inconnu « ${r.etat} »`)
|
||||
if (!dans(ETATS, r.etat)) err(id, r.type, `etat inconnu « ${r.etat} »`)
|
||||
|
||||
const de = parId.get(r.de)
|
||||
if (!de) { err(id, 'orpheline', `${r.type} : « ${r.de} » n’est pas dans le jeu`); continue }
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* vocabulaire — B19b M4. Le vocabulaire du schéma de la couche (natures, échelles, couches,
|
||||
* préfixes, états, seuil de copie), écrit UNE fois. Le schéma (`data/connaissances/schema.json`)
|
||||
* reste le contrat : `scripts/test-connaissances.mjs` compare chaque liste à son énumération,
|
||||
* et les préfixes aux motifs `^txt:`… du schéma. Écrit ici plutôt que lu dans le JSON pour
|
||||
* deux raisons : des types littéraux (`Nature`, `Echelle`) sans recopie, et un adaptateur
|
||||
* (`useFicheAdapter`, servi sur `/`, `/agences`, `/outils`) qui n'embarque pas le schéma.
|
||||
* Importé par `valider.ts`, `lire.ts`, `useFicheAdapter.ts`, la page et le test.
|
||||
*/
|
||||
|
||||
/** Les quatre natures, dans l'ordre du schéma (`$defs.objet.properties.nature.enum`). */
|
||||
export const NATURES = ['texte', 'organisation', 'outil', 'concept'] as const
|
||||
export type Nature = (typeof NATURES)[number]
|
||||
|
||||
/** Préfixe d'identifiant de chaque nature (`$defs.id.pattern` et les `allOf` du schéma). */
|
||||
export const PREFIXES: Record<Nature, string> = { texte: 'txt', organisation: 'org', outil: 'out', concept: 'cpt' }
|
||||
|
||||
/** Échelles S / M / XL, dans l'ordre d'affichage (`$defs.objet.properties.echelles.items.enum`). */
|
||||
export const ECHELLES = ['S', 'M', 'XL'] as const
|
||||
export type Echelle = (typeof ECHELLES)[number]
|
||||
|
||||
/** Couches (`$defs.objet.properties.couche.enum`). */
|
||||
export const COUCHES = ['socle', 'actualite'] as const
|
||||
export type Couche = (typeof COUCHES)[number]
|
||||
|
||||
/** États d'un objet ou d'une relation (`$defs.etat.enum`). */
|
||||
export const ETATS = ['en_file', 'a_trier', 'publie', 'a_creuser', 'ecarte'] as const
|
||||
export type Etat = (typeof ETATS)[number]
|
||||
|
||||
/** Le seul état rendu en public : tout autre attend un humain (CONCEPTION §5, interdit n° 2). */
|
||||
export const ETAT_RENDU: Etat = 'publie'
|
||||
|
||||
/**
|
||||
* Longueur au-delà de laquelle une suite de mots commune à la définition et au libellé de la
|
||||
* source est une copie (règle `copie` du validateur). Le schéma ne la porte pas : elle vit ici.
|
||||
*/
|
||||
export const MOTS_COPIE_MAX = 12
|
||||
|
||||
export const LIBELLES_NATURE: Record<Nature, string> = {
|
||||
concept: 'Concept',
|
||||
texte: 'Texte',
|
||||
organisation: 'Organisation',
|
||||
outil: 'Outil',
|
||||
}
|
||||
|
||||
export const LIBELLES_COUCHE: Record<Couche, string> = { socle: 'Socle', actualite: 'Actualité' }
|
||||
|
||||
/** Motif d'un préfixe de nature en tête d'identifiant (`cpt:`, `org:`…), tiré de `PREFIXES`. */
|
||||
export const RE_PREFIXE = new RegExp(`^(${Object.values(PREFIXES).join('|')}):`)
|
||||
Reference in New Issue
Block a user