/** * Adds the set of attacks to this Dung theory. * @param c a collection of attacks * @return "true" if this Dung theory has been modified. */ public boolean addAllAttacks(Collection<? extends Attack> c){ boolean result = false; for(Attack att: c) result |= this.add(att); return result; }
@Override public Graph<Argument> getRestriction(Collection<Argument> arguments) { DungTheory theory = new DungTheory(); theory.addAll(arguments); for (Attack attack: this.getAttacks()) if(arguments.contains(attack.getAttacked()) && arguments.contains(attack.getAttacker())) theory.add(attack); return theory; }
@Override public DungTheory parse(Reader reader) throws IOException { DungTheory theory = new DungTheory(); BufferedReader in = new BufferedReader(reader); String row = null; boolean argumentSection = true; Map<String,Argument> arguments = new HashMap<String,Argument>(); while ((row = in.readLine()) != null) { if(row.trim().equals("")) continue; if(row.trim().equals("#")){ argumentSection = false; continue; } if(argumentSection) { Argument a = new Argument(row.trim()); arguments.put(a.getName(), a); theory.add(a); } else{ theory.addAttack(arguments.get(row.substring(0, row.indexOf(" ")).trim()),arguments.get(row.substring(row.indexOf(" ")+1,row.length()).trim())); } } in.close(); return theory; } }
newTheory.addAll(theory); newTheory.addAllAttacks(theory.getAttacks()); newTheory.add(new Attack(a,b)); if(!this.isIsomorphic(newTheory, newTheories)) newTheories.add(newTheory); DungTheory theory = new DungTheory(); for(int i = 0; i < this.cntArguments; i++) theory.add(new Argument("A"+i)); this.currentTheories.clear(); this.currentTheories.add(theory);
/** * Generates a Dung theory with a tree shape where the given argument * is the root. * @param arg some argument. * @return a Dung theory. */ private DungTheory generateTreeShape(Argument arg){ DungTheory theory = new DungTheory(); theory.add(arg); int numOfArguments = 1; Queue<Argument> q = new LinkedList<Argument>(); q.add(arg); while(numOfArguments < this.params.numberOfArguments){ Argument a = new Argument("a" + numOfArguments++); theory.add(new Attack(a, (Argument)theory.toArray()[this.random.nextInt(numOfArguments-1)])); theory.add(a); } return theory; }
@Override public DungTheory next() { if(this.attacks == null){ this.currentSize = 1; this.arguments = new HashSet<Argument>(); arguments.add(new Argument("A1")); this.possibleAttacks = this.generatePossibleAttacks(arguments); this.attacks = new BitSet(this.possibleAttacks.size()); }else{ if(this.addOneToBitSet(this.attacks, this.possibleAttacks.size())){ this.currentSize++; this.arguments = new HashSet<Argument>(); for(int i = 0; i < this.currentSize;i++) arguments.add(new Argument("A"+i)); this.possibleAttacks = this.generatePossibleAttacks(this.arguments); this.attacks = new BitSet(this.possibleAttacks.size()); } } DungTheory theory = new DungTheory(); theory.addAll(this.arguments); for(int i = 0; i < this.possibleAttacks.size(); i++) if(this.attacks.get(i)) theory.add(this.possibleAttacks.get(i)); return theory; }
public static void main(String[] args){ // create some Dung theory DungTheory theory = new DungTheory(); Argument a = new Argument("a"); Argument b = new Argument("b"); Argument c = new Argument("c"); Argument d = new Argument("d"); //Argument e = new Argument("e"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); //theory.add(e); theory.add(new Attack(a,b)); theory.add(new Attack(b,a)); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(d,c)); theory.add(new Attack(c,d)); StratifiedLabelingReasoner reasoner = new StratifiedLabelingReasoner(Semantics.STABLE_SEMANTICS); for(StratifiedLabeling labeling: reasoner.getModels(theory)){ System.out.println(labeling); } } }
public static void main(String[] args){ // create some Dung theory DungTheory theory = new DungTheory(); Argument a = new Argument("a"); Argument b = new Argument("b"); Argument c = new Argument("c"); Argument d = new Argument("d"); Argument e = new Argument("e"); Argument f = new Argument("f"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); theory.add(e); theory.add(f); theory.add(new Attack(a,b)); theory.add(new Attack(b,c)); theory.add(new Attack(c,d)); theory.add(new Attack(d,e)); theory.add(new Attack(e,a)); theory.add(new Attack(e,f)); SimpleCF2Reasoner reasoner = new SimpleCF2Reasoner(); for(Extension ext: reasoner.getModels(theory)){ System.out.println(ext); } } }
theory.add(arg); theory.add(d); theory.add(b); theory.add(c); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(b,arg)); theory.add(new Attack(c,arg)); cn = new Argument("c" + idx); idx++; theory.add(bn); theory.add(cn); theory.add(new Attack(bn,b)); theory.add(new Attack(cn,c)); b = new Argument("b" + idx); c = new Argument("c" + idx); theory.add(b); theory.add(c); theory.add(new Attack(b,bn)); theory.add(new Attack(b,cn)); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(c,bn)); theory.add(new Attack(c,cn)); idx++; theory.add(new Attack(d,b));
@Override public DungTheory getComplementGraph(int selfloops) { DungTheory comp = new DungTheory(); for(Argument node: this) comp.add(node); for(Argument node1: this) for(Argument node2: this) if(node1 == node2){ if(selfloops == Graph.INVERT_SELFLOOPS){ if(!this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); }else if(selfloops == Graph.IGNORE_SELFLOOPS){ if(this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); } }else if(!this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); return comp; }
Argument f = new Argument("f"); Argument g = new Argument("g"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); theory.add(e); theory.add(f); theory.add(g); theory.add(new Attack(d,c)); theory.add(new Attack(c,a)); theory.add(new Attack(a,b)); theory.add(new Attack(b,a)); theory.add(new Attack(e,b)); theory.add(new Attack(f,e)); theory.add(new Attack(g,e));
@Override public DungTheory next() { if(this.params.enforceTreeShape) return this.generateTreeShape(new Argument("a")); DungTheory theory = new DungTheory(); for(int i = 0; i < this.params.numberOfArguments; i++) theory.add(new Argument("a" + i)); for(Argument a: theory) for(Argument b: theory){ if(a == b && this.params.avoidSelfAttacks) continue; if(this.random.nextDouble() <= this.params.attackProbability) theory.add(new Attack(a,b)); } return theory; }
/** * @return a Dung Theory derived from this ABA theory */ public DungTheory asDungTheory() { if (!isFlat()) throw new RuntimeException("Only flat ABA theories can be transformed into Dung theories."); Collection<Deduction<T>> ds = getAllDeductions(); int id = 0; DungTheory dt = new DungTheory(); Map<Deduction<T>, Argument> argmap = new HashMap<>(); for (Deduction<T> d : ds) { Argument arg = d.getRule() instanceof Assumption<?> ? new Argument(d.getConclusion().toString()) : new Argument("arg_" + id++); dt.add(arg); argmap.put(d, arg); } for (Deduction<T> atter : ds) for (Deduction<T> atted : ds) for (T ass : atted.getAssumptions()) if (attacks(atter, ass)) { dt.add(new Attack(argmap.get(atter), argmap.get(atted))); break; } return dt; }
@Override public DungTheory next(Argument arg){ DungTheory theory = new DungTheory(); if(this.params.enforceTreeShape){ boolean inExtension = false; do{ theory = this.generateTreeShape(arg); inExtension = new SimpleGroundedReasoner().query(theory,arg); }while(!inExtension); return theory; } theory.add(arg); for(int i = 1; i < this.params.numberOfArguments; i++) theory.add(new Argument("a" + i)); for(Argument a: theory) for(Argument b: theory){ if(a == b && this.params.avoidSelfAttacks) continue; if(this.random.nextDouble() <= this.params.attackProbability){ Attack att = new Attack(a,b); theory.add(att); //Check whether this makes the argument out if(!new SimpleGroundedReasoner().query(theory,arg)) theory.remove(att); } } return theory; }
/** * This method translates this delp into an abstract Dung theory. All arguments, that can * be built in this theory are interpreted as abstract arguments. The attack relation is built using * the dialectical proof theory of delp. * @return the abstract Dung theory induced by this delp. */ public DungTheory getDungTheory(){ DungTheory dungTheory = new DungTheory(); for (DelpArgument arg1 : getArguments()) { //add arguments dungTheory.add(new Argument(arg1.toString())); //add attacks for (DelpArgument arg2 : getArguments()) { if (arg1.getDisagreementSubargument(arg2.getConclusion(), this) != null) { dungTheory.add(new Attack(new Argument(arg2.toString()), new Argument(arg1.toString()))); } } } return dungTheory; }