# --- M4 SW-15 : copie pedagogique declaree (pont AIF + projection AF + grounded) ---
from rdflib import Graph, Namespace
AIF = Namespace("http://www.arg.dundee.ac.uk/aif#")
AX = Namespace("http://example.org/aif-ext#")
def _ra(g, nid, scheme, premises, conclusion):
g.add((AX[nid], RDF.type, AIF["RA-node"]))
g.add((AX[nid], AIF.scheme, scheme))
for p in premises: g.add((AX[nid], AIF.Premise, AX[p]))
g.add((AX[nid], AIF.Conclusion, AX[conclusion]))
def _ca(g, nid, attacker, target):
g.add((AX[nid], RDF.type, AIF["CA-node"]))
g.add((AX[nid], AX["from"], AX[attacker]))
g.add((AX[nid], AIF.aifAttackedNode, AX[target]))
def _af(g):
args = {s for s,_,_ in g.triples((None, RDF.type, AIF["RA-node"]))}
prem = {}
for ra,_,i in g.triples((None, AIF.Premise, None)): prem.setdefault(i, set()).add(ra)
attacks = set()
for ca,_,_ in g.triples((None, RDF.type, AIF["CA-node"])):
frm = next(g.objects(ca, AX["from"]), None)
tgt = next(g.objects(ca, AIF.aifAttackedNode), None)
if frm is None or tgt is None: continue
if tgt in args: attacks.add((frm, tgt))
for owner in prem.get(tgt, ()):
if owner != frm: attacks.add((frm, owner))
return args, attacks
def _grounded(args, attacks):
att = {a: {b for (b,t) in attacks if t == a} for a in args}
lab = {a: "UNDEC" for a in args}; ch = True
while ch:
ch = False
for a in args:
if lab[a] != "UNDEC": continue
if any(lab[b]=="IN" for b in att[a]): lab[a]="OUT"; ch=True
elif all(lab[b]=="OUT" for b in att[a]): lab[a]="IN"; ch=True
return {a for a in args if lab[a]=="IN"}
g_base = Graph()
for s in ["ExpertOpinion","NegativeConsequences","Example","Bias"]:
g_base.add((AIF[s], RDF.type, AIF.Inference_Scheme))
for nid, sch, prem, concl in [
("RA1", AIF.ExpertOpinion, ["I1"], "C1"),
("RA2", AIF.NegativeConsequences, ["I2"], "C2"),
("RA3", AIF.Example, ["I4"], "C1"),
("RA4", AIF.Bias, ["I5"], "I6")]:
_ra(g_base, nid, AIF[sch], prem, concl)
_ca(g_base, "CA1", "RA2", "RA1"); _ca(g_base, "CA2", "RA1", "RA2"); _ca(g_base, "CA3", "RA4", "I4")
g_ext = Graph()
for t in g_base: g_ext.add(t)
g_ext.add((AX.RepresentativeSample, RDF.type, AIF.Inference_Scheme)) # NOUVEAU SCHEME
_ra(g_ext, "RA5", AX.RepresentativeSample, ["I7"], "I8")
_ca(g_ext, "CA4", "RA5", "I5")
def _noms(s): return sorted(x.split("#")[-1] for x in s)
args_b, att_b = _af(g_base); args_e, att_e = _af(g_ext)
print("AVANT :", len(args_b), "args /", len(att_b), "attaques, grounded =", _noms(_grounded(args_b, att_b)))
print("APRES :", len(args_e), "args /", len(att_e), "attaques, grounded =", _noms(_grounded(args_e, att_e)))
# --- Transcription : le nouveau SCHEME est un concept, RA5 une action nouvelle ---
g0 = EvolutiveGame(
agents=("argumenteur","juge"),
lexicon=frozenset(["ExpertOpinion","NegativeConsequences","Example","Bias"]),
actions=frozenset(f"arguer {x}" for x in ["RA1","RA2","RA3","RA4"]),
payoffs={(a, f"arguer {x}"): 0.5 for a in ("argumenteur","juge")
for x in ["RA1","RA2","RA3","RA4"]})
eta4 = OntologicalMove(proposer="argumenteur", new_concepts=("RepresentativeSample",),
opened_actions={"RepresentativeSample": ("arguer RA5",)})
g1 = apply_ontology(g0, eta4)
v4 = bancher_mecanisme("SW-15 (AF + nouveau scheme)", g0, g1, eta4, (eta4,),
equivalence=None, horizon=40, n_sim=80,
rng=np.random.default_rng(3))
print(f"\nO_t={v4.O_t} dA_t={v4.dA_t} C_t={v4.C_t} inst={v4.institutionnalisation:.3f} "
f"P_R_marg={v4.P_R_marg:.3f}")
print("CLASSE :", v4.classe, " (lecture rapide prevoyait 'latent')")