/** * Dump the learning result to file {@link CommandOptions#fout}. The format of this file is * consistent with inference part. */ public void dumpAnswers(String fout) { ArrayList<String> lines = new ArrayList<String>(); DecimalFormat twoDForm = new DecimalFormat("#.####"); HashSet<Predicate> allp = mln.getAllPred(); for (Predicate p : allp) { String s = ""; if (p.isClosedWorld()) { // System.out.print("*"); s += "*"; } // System.out.print(p.getName() + "("); s += p.getName() + "("; for (int i = 0; i < p.arity(); i++) { // System.out.print(p.getTypeAt(i).name()); s += p.getTypeAt(i).name(); if (i != p.arity() - 1) { // System.out.print(","); s += ","; } } // System.out.println(")"); s += ")"; lines.add(s); } lines.add("\n"); // System.out.println(); lines.add("//////////////AVERAGE WEIGHT OF ALL THE ITERATIONS//////////////"); Object[] keySet = currentWeight.keySet().toArray(); java.util.Arrays.sort(keySet); for (Object ss : keySet) { String s = (String) ss; String sid = s.replace("fixed", "").replace("check", "").replace("hard", ""); // System.out.println(s + "\t" + Learner.currentWeight.get(s) + ":" + // this.trainingSatisification.get(s) + "/" + this.trainingViolation.get(s) + // "\t" + Clause.mappingFromID2Desc.get(s)); if (s.contains("hardfixed")) { lines.add(Clause.mappingFromID2Desc.get(sid).replaceAll("^\\s+", "") + ". //" + s); } else { // System.out.println("~~~" + sid + "~~~~" + Learner.finalWeight.get(s)); lines.add( twoDForm.format(Learner.finalWeight.get(s)) + " " + Clause.mappingFromID2Desc.get(sid) + " //" + s); } } lines.add("\n"); lines.add("//////////////WEIGHT OF LAST ITERATION//////////////"); keySet = currentWeight.keySet().toArray(); java.util.Arrays.sort(keySet); for (Object ss : keySet) { String s = (String) ss; String sid = s.replace("fixed", "").replace("check", "").replace("hard", ""); // System.out.println(s + "\t" + Learner.currentWeight.get(s) + ":" + // this.trainingSatisification.get(s) + "/" + this.trainingViolation.get(s) + // "\t" + Clause.mappingFromID2Desc.get(s)); if (s.contains("hardfixed")) { lines.add(Clause.mappingFromID2Desc.get(sid).replaceAll("^\\s+", "") + ". //" + s); } else { // System.out.println("~~~" + sid + "~~~~" + Learner.finalWeight.get(s)); lines.add( twoDForm.format(Learner.finalWeight.get(s)) + " " + Clause.mappingFromID2Desc.get(sid) + " //" + s); } } lines.add("\n\n"); FileMan.writeToFile(fout, StringMan.join("\n", lines)); }