// On ajoute un 3e argument C qui refute B seulement (arbitre).
// Sous evcxr rien ne persiste : cette cellule redefinit A, B (litteraux
// identiques a la cellule precedente) et tout l'arsenal de Dung.
use std::collections::BTreeSet;
struct ToulminArgument {
name: &'static str,
claim: &'static str,
data: &'static str,
warrant: &'static str,
backing: &'static str,
qualifier: &'static str,
rebuttal_targets: BTreeSet<&'static str>,
}
impl ToulminArgument {
fn new(name: &'static str, claim: &'static str, data: &'static str, warrant: &'static str,
backing: &'static str, qualifier: &'static str,
rebuttal_targets: &[&'static str]) -> Self {
ToulminArgument {
name,
claim,
data,
warrant,
backing,
qualifier,
rebuttal_targets: rebuttal_targets.iter().copied().collect(),
}
}
/// True si les 3 composants essentiels sont presents (claim/data/warrant).
fn is_complete(&self) -> bool {
!self.claim.is_empty() && !self.data.is_empty() && !self.warrant.is_empty()
}
/// Liste des composants essentiels manquants (pour diagnostic).
fn missing_pieces(&self) -> Vec<&'static str> {
let mut missing = Vec::new();
if self.claim.is_empty() {
missing.push("claim");
}
if self.data.is_empty() {
missing.push("data");
}
if self.warrant.is_empty() {
missing.push("warrant");
}
missing
}
/// Affiche l'argument deploye en ses 6 pieces.
fn describe(&self) -> String {
let rt: Vec<&str> = if self.rebuttal_targets.is_empty() {
vec!["(aucun)"]
} else {
self.rebuttal_targets.iter().copied().collect()
};
[
format!("[{}] Argument Toulmin (complet: {})", self.name, py_bool(self.is_complete())),
format!(" Claim : {}", or_fallback(self.claim, "(manquant)")),
format!(" Data : {}", or_fallback(self.data, "(manquant)")),
format!(" Warrant : {}", or_fallback(self.warrant, "(manquant)")),
format!(" Backing : {}", or_fallback(self.backing, "(non precise)")),
format!(" Qualifier: {}", or_fallback(self.qualifier, "(non precise)")),
format!(" Rebuttals cibles: {}", fmt_str_list(&rt)),
]
.join("\n")
}
}
/// Equivalent Rust de l'affichage Python d'un booleen (True/False).
fn py_bool(b: bool) -> &'static str {
if b { "True" } else { "False" }
}
/// Liste Python ['a', 'b'] : apostrophes simples, virgule-espace, crochets.
fn fmt_str_list(items: &[&str]) -> String {
let inner: Vec<String> = items.iter().map(|s| format!("'{}'", s)).collect();
format!("[{}]", inner.join(", "))
}
/// Idiome Python `x or '(manquant)'` : chaine vide -> fallback.
fn or_fallback<'a>(s: &'a str, fb: &'a str) -> &'a str {
if s.is_empty() { fb } else { s }
}
/// Cadre d'argumentation abstrait de Dung (arguments + relation d'attaque).
struct Af {
args: BTreeSet<&'static str>,
attacks: BTreeSet<(&'static str, &'static str)>,
}
impl Af {
fn attackers(&self, x: &str) -> BTreeSet<&'static str> {
self.attacks
.iter()
.filter(|(_, b)| *b == x)
.map(|(a, _)| *a)
.collect()
}
}
/// S defait x si un membre de S attaque x.
fn defeats(af: &Af, s: &BTreeSet<&str>, x: &str) -> bool {
af.attacks.iter().any(|(a, b)| *b == x && s.contains(a))
}
/// S defend x si S defait chaque attaquant de x.
fn defends(af: &Af, s: &BTreeSet<&str>, x: &str) -> bool {
af.attackers(x).iter().all(|b| defeats(af, s, b))
}
/// Extension grounded : point fixe E -> E union {x defendu par E}.
fn grounded(af: &Af) -> BTreeSet<&'static str> {
let mut e: BTreeSet<&'static str> = BTreeSet::new();
loop {
let mut e_new = e.clone();
for x in &af.args {
if defends(af, &e, x) {
e_new.insert(x);
}
}
if e_new == e {
return e;
}
e = e_new;
}
}
/// Traduit un debat d'arguments Toulmin en un cadre de Dung :
/// chaque rebuttal_target (A refute B) devient une attaque (A -> B).
fn toulmin_debate_to_af(arguments: &[&ToulminArgument]) -> Af {
let names: BTreeSet<&'static str> = arguments.iter().map(|a| a.name).collect();
let mut attacks: BTreeSet<(&'static str, &'static str)> = BTreeSet::new();
for a in arguments {
for tgt in &a.rebuttal_targets {
if names.contains(tgt) {
// ne cree l'attaque que si la cible existe
attacks.insert((a.name, *tgt));
}
}
}
Af { args: names, attacks }
}
/// Liste Python de tuples : [('A', 'B'), ('B', 'A')] — BTreeSet itere trie,
/// exactement le sorted() lexicographique Python sur tuples.
fn fmt_attack_list(attacks: &BTreeSet<(&'static str, &'static str)>) -> String {
let inner: Vec<String> = attacks
.iter()
.map(|(a, b)| format!("('{}', '{}')", a, b))
.collect();
format!("[{}]", inner.join(", "))
}
let a = ToulminArgument::new(
"A",
"Le projet X doit etre finance",
"X a un ROI projete de 15%",
"Les projets a ROI eleve meritent financement",
"Principe d'allocation rationnelle du capital",
"probablement",
&["B"], // A refute B
);
let b = ToulminArgument::new(
"B",
"Le projet X ne doit pas etre finance",
"X presente un risque de defaut de 40%",
"Les projets trop risques doivent etre evites",
"Principe de prudence",
"possiblement",
&["A"], // B refute A
);
let c = ToulminArgument::new(
"C",
"Le risque de defaut de X est surestime",
"L'historique montre 10% de defaut reel sur projets similaires",
"Les projections de risque doivent etre calibrees sur donnees passees",
"Principe de calibration empirique",
"fortement",
&["B"], // C refute B, MAIS PAS A
);
println!("=== Debat a 3 arguments (C arbitre en refutant B) ===");
println!("{}", c.describe());
println!();
let af3 = toulmin_debate_to_af(&[&a, &b, &c]);
let args3: Vec<&str> = af3.args.iter().copied().collect();
println!("Cadre de Dung : args={}", fmt_str_list(&args3));
println!(" attacks={}", fmt_attack_list(&af3.attacks));
let g3 = grounded(&af3);
println!("Extension grounded : {}", fmt_str_list(&g3.iter().copied().collect::<Vec<&str>>()));
println!();
println!(">>> Lecture : C defait B -> B ne peut plus attaquer A -> A est defendu.");
println!(" Les claims A et C survivent ; B (le contre-argument) est exclu.");
println!(" Le warrant sous-jacent : un seul arbitre peut faire basculer un debat");
println!(" indécis vers une conclusion, SANS toucher aux arguments principaux.");