// Path: src/main/java/de/tudarmstadt/ukp/dkpro/argumentation/crossdomainclaims/utils/ArgUtils.java
// public class ArgUtils {
// 
// 	
// 	public static String getID(String s) {
// 		String[] tmp = s.split("/");
// 		return tmp[tmp.length-1].replace(".xmi","").replace(".bin", "");
// 	}
// 	
// 	
// 	public static String getID(File f) {
// 		return getID(f.getName());
// 	}
// 	
// 	
// 	public static boolean isClaim(Sentence s, JCas cas) {
// 		return selectOverlapping(Claim.class, s, cas).size()>0 || selectOverlapping(MajorClaim.class, s, cas).size()>0;
// 	}
// 	
// 	
// 	public static boolean isPremise(Sentence s, JCas cas) {
// 		return selectOverlapping(Premise.class, s, cas).size()>0;
// 	}
// 	
// 	
// 	public static <T extends TOP> List<T> selectOverlapping(Class<T> type,Annotation annotation, JCas jCas) {
//         Collection<T> allAnnotations = JCasUtil.select(jCas, type);
// 
//         List<T> result = new ArrayList<T>();
// 
//         for (T a : allAnnotations) {
//             if ((a instanceof Annotation) && (doOverlap(annotation, (Annotation) a))) {
//                 result.add(a);
//             }
//         }
// 
//         return result;
//     }
// 	
// 	 
// 	public static <T extends Annotation> boolean doOverlap(final T anno1, final T anno2) {
// 		return anno1.getEnd() > anno2.getBegin() && anno1.getBegin() < anno2.getEnd();
// 	}
// 	
// 	
// 	public static JCas readCas(File f) throws ResourceInitializationException, SAXException, IOException, CASException {
// 		CAS loadedCas = CasCreationUtils.createCas(TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null); 
// 		FileInputStream in = new FileInputStream(f); 
// 		XmiCasDeserializer.deserialize(in, loadedCas);
// 		IOUtils.closeQuietly(in);
// 		return loadedCas.getJCas();
// 	}
// 	
// 	public static void writeFile(String fileName, String content) throws Exception {
// 		BufferedWriter br = new BufferedWriter(new FileWriter(new File(fileName)));
// 		br.write(content);
// 		br.close();
// 	}
// 	
// 	
// }


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.Table;
import com.google.common.collect.TreeBasedTable;
import de.tudarmstadt.ukp.dkpro.argumentation.crossdomainclaims.utils.ArgUtils;
import de.tudarmstadt.ukp.dkpro.tc.weka.report.WekaClassificationReport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FileFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import java.io.*;
import java.text.NumberFormat;
                    if (subFolder.getName().contains("TestTask")) {
                        FileUtils
                                .copyFile(new File(subFolder.getAbsoluteFile() + "/id2outcome.txt"),
                                        new File(resultFilePath + "/" + ExperimentUtils.OUTCOME_PATH
                                                + "/id2outcome" + String.format("%03d", oCounter)
                                                + ".txt"));
                        oCounter++;
                    }
                }

                // get scores
                StringBuilder sb = new StringBuilder();
                double sumAcc = 0.0;
                double sumF1 = 0.0;
                File matrices = new File(resultFilePath + "/" + ExperimentUtils.MATRIX_PATH);
                double folds = 0.0;
                for (File cm : matrices.listFiles()) {
                    if (!cm.getName().endsWith(".csv"))
                        continue;
                    ConfusionMatrix c = new ConfusionMatrix(cm);
                    sb.append(c.Fmacro() + "\n");
                    sumF1 += c.Fmacro();
                    sumAcc += c.Acc();
                    folds++;
                }
                NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.US);
                percentFormat.setMaximumFractionDigits(3);
                String results = "Accuracy = " + (percentFormat.format(sumAcc / folds)) + "\n";
                results += "Macro-F1 = " + (percentFormat.format(sumF1 / folds));
                System.out.println(results);
// Path: src/main/java/de/tudarmstadt/ukp/dkpro/argumentation/crossdomainclaims/utils/ArgUtils.java
// public class ArgUtils {
// 
// 	
// 	public static String getID(String s) {
// 		String[] tmp = s.split("/");
// 		return tmp[tmp.length-1].replace(".xmi","").replace(".bin", "");
// 	}
// 	
// 	
// 	public static String getID(File f) {
// 		return getID(f.getName());
// 	}
// 	
// 	
// 	public static boolean isClaim(Sentence s, JCas cas) {
// 		return selectOverlapping(Claim.class, s, cas).size()>0 || selectOverlapping(MajorClaim.class, s, cas).size()>0;
// 	}
// 	
// 	
// 	public static boolean isPremise(Sentence s, JCas cas) {
// 		return selectOverlapping(Premise.class, s, cas).size()>0;
// 	}
// 	
// 	
// 	public static <T extends TOP> List<T> selectOverlapping(Class<T> type,Annotation annotation, JCas jCas) {
//         Collection<T> allAnnotations = JCasUtil.select(jCas, type);
// 
//         List<T> result = new ArrayList<T>();
// 
//         for (T a : allAnnotations) {
//             if ((a instanceof Annotation) && (doOverlap(annotation, (Annotation) a))) {
//                 result.add(a);
//             }
//         }
// 
//         return result;
//     }
// 	
// 	 
// 	public static <T extends Annotation> boolean doOverlap(final T anno1, final T anno2) {
// 		return anno1.getEnd() > anno2.getBegin() && anno1.getBegin() < anno2.getEnd();
// 	}
// 	
// 	
// 	public static JCas readCas(File f) throws ResourceInitializationException, SAXException, IOException, CASException {
// 		CAS loadedCas = CasCreationUtils.createCas(TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null); 
// 		FileInputStream in = new FileInputStream(f); 
// 		XmiCasDeserializer.deserialize(in, loadedCas);
// 		IOUtils.closeQuietly(in);
// 		return loadedCas.getJCas();
// 	}
// 	
// 	public static void writeFile(String fileName, String content) throws Exception {
// 		BufferedWriter br = new BufferedWriter(new FileWriter(new File(fileName)));
// 		br.write(content);
// 		br.close();
// 	}
// 	
// 	
// }


// Path: src/main/java/de/tudarmstadt/ukp/dkpro/argumentation/crossdomainclaims/experiments/utils/ExperimentUtils.java
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.Table;
import com.google.common.collect.TreeBasedTable;
import de.tudarmstadt.ukp.dkpro.argumentation.crossdomainclaims.utils.ArgUtils;
import de.tudarmstadt.ukp.dkpro.tc.weka.report.WekaClassificationReport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FileFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import java.io.*;
import java.text.NumberFormat;

                    if (subFolder.getName().contains("TestTask")) {
                        FileUtils
                                .copyFile(new File(subFolder.getAbsoluteFile() + "/id2outcome.txt"),
                                        new File(resultFilePath + "/" + ExperimentUtils.OUTCOME_PATH
                                                + "/id2outcome" + String.format("%03d", oCounter)
                                                + ".txt"));
                        oCounter++;
                    }
                }

                // get scores
                StringBuilder sb = new StringBuilder();
                double sumAcc = 0.0;
                double sumF1 = 0.0;
                File matrices = new File(resultFilePath + "/" + ExperimentUtils.MATRIX_PATH);
                double folds = 0.0;
                for (File cm : matrices.listFiles()) {
                    if (!cm.getName().endsWith(".csv"))
                        continue;
                    ConfusionMatrix c = new ConfusionMatrix(cm);
                    sb.append(c.Fmacro() + "\n");
                    sumF1 += c.Fmacro();
                    sumAcc += c.Acc();
                    folds++;
                }
                NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.US);
                percentFormat.setMaximumFractionDigits(3);
                String results = "Accuracy = " + (percentFormat.format(sumAcc / folds)) + "\n";
                results += "Macro-F1 = " + (percentFormat.format(sumF1 / folds));
                System.out.println(results);
                ArgUtils.writeFile(resultFilePath + "/Results.txt", results);