/** * Writes the given collection of arguments into a string of the form * [arg1,...,argn]. * @param args some collection of arguments * @return a string representation of the collection of arguments */ public static String writeArguments(Collection<Argument> args){ String s = "["; boolean first = true; for(Argument a: args){ if(first){ s += a.getName(); first = false; }else{ s += "," + a.getName(); } } s += "]"; return s; }
@Override public void write(DungTheory aaf, File f) throws IOException { PrintWriter writer = new PrintWriter(f, "UTF-8"); for(Argument a: aaf) writer.println("arg(" + a.getName() + ")."); for(Attack att: aaf.getAttacks()) writer.println("att(" + att.getAttacker().getName() + "," + att.getAttacked().getName() + ")."); writer.close(); }
@Override public void write(DungTheory aaf, File f) throws IOException { PrintWriter writer = new PrintWriter(f, "UTF-8"); for(Argument a: aaf) writer.println(a.getName()); writer.println("#"); for(Attack att: aaf.getAttacks()) writer.println(att.getAttacker().getName() + " " + att.getAttacked().getName()); writer.close(); }
for(Argument a: l.getArgumentsOfStatus(ArgumentStatus.IN)) if(first){ result += a.getName(); first = false; }else result += "," + a.getName(); result += "],["; first = true; for(Argument a: l.getArgumentsOfStatus(ArgumentStatus.OUT)) if(first){ result += a.getName(); first = false; }else result += "," + a.getName(); result += "],["; first = true; for(Argument a: l.getArgumentsOfStatus(ArgumentStatus.UNDECIDED)) if(first){ result += a.getName(); first = false; }else result += "," + a.getName(); result +="]]"; return result;
@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; } }
@Override public Boolean query(DungTheory beliefbase, Argument formula, InferenceMode inferenceMode) { // first check whether the solver supports the problem String inf; if(inferenceMode.equals(InferenceMode.SKEPTICAL)) inf = "DS"; else inf = "DC"; ProboProblem problem = ProboProblem.getProblem(inf + "-" + this.semantics.abbreviation()); if(!this.supportedProblems().contains(problem)) throw new UnsupportedOperationException("Problem not supported by this probo solver."); FileFormat format; if(this.supportedFormats().contains(FileFormat.TGF)) format = FileFormat.TGF; else if(this.supportedFormats().contains(FileFormat.APX)) format = FileFormat.APX; else format = this.supportedFormats().iterator().next(); try { File temp = File.createTempFile("aaf-", "." + format.extension()); AbstractDungWriter writer = AbstractDungWriter.getWriter(format); writer.write(beliefbase, temp); String result = this.bash.run(this.path_to_exec + " -p " + problem.toString() + " -fo " + format.toString() + " -f " + temp.getAbsolutePath() + " -a " + formula.getName()); temp.delete(); return AbstractDungParser.parseBoolean(result); } catch (Exception e) { throw new RuntimeException(e); } }