<commit_before>package edu.neu.ccs.pyramid.application;

import edu.neu.ccs.pyramid.calibration.CTAT;
import edu.neu.ccs.pyramid.calibration.CTFT;
import edu.neu.ccs.pyramid.configuration.Config;
import edu.neu.ccs.pyramid.dataset.*;
import edu.neu.ccs.pyramid.eval.FMeasure;
import edu.neu.ccs.pyramid.eval.Precision;
import edu.neu.ccs.pyramid.eval.Recall;
import edu.neu.ccs.pyramid.regression.IsotonicRegression;
import edu.neu.ccs.pyramid.util.FileUtil;
import edu.neu.ccs.pyramid.util.Pair;
import edu.neu.ccs.pyramid.util.ReportUtils;
import edu.neu.ccs.pyramid.util.Serialization;
import org.apache.commons.io.FileUtils;
import sun.rmi.runtime.Log;

import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AppCombSUM {


    public static void main(String[] args)throws Exception{
        if (args.length !=1){
            throw new IllegalArgumentException("Please specify a properties file.");
        }

        Config config = new Config(args[0]);
        Logger logger = Logger.getAnonymousLogger();
        String logFile = config.getString("output.log");
        FileHandler fileHandler = null;
        if (!logFile.isEmpty()){
            new File(logFile).getParentFile().mkdirs();
            //todo should append?
            fileHandler = new FileHandler(logFile, true);
            Formatter formatter = new SimpleFormatter();
            fileHandler.setFormatter(formatter);
            logger.addHandler(fileHandler);
            logger.setUseParentHandlers(false);
        }

        logger.info(config.toString());


        File output = new File(config.getString("output.folder"));
        output.mkdirs();



        if (config.getBoolean("calibrate")){
            calibrate(config,logger);
        }


        if (config.getBoolean("validate")){
            report(config,config.getString("validFolder"));
        }


        if(config.getBoolean("tuneThreshold")){
            tuneThreshold(config,logger);

        }

        if (config.getBoolean("test")){
            report(config,config.getString("testFolder"));
            testAutomation(config,logger);
        }


        if (fileHandler!=null){
            fileHandler.close();
        }

    }


    private static IsotonicRegression trainIsoRegression(Map<String,Pair<MultiLabel,Double>> map,Config config,LabelTranslator labelTranslator,Map<String,String> groundTruth)throws Exception {
        List<String> modelPaths = config.getStrings("modelPaths");
        String calibFolder = config.getString("calibFolder");
        List<String> docIds = ReportUtils.getDocIds(Paths.get(modelPaths.get(0),"predictions",calibFolder+"_reports","report.csv").toString());
        double[] locations = new double[docIds.size()];
        double[] numbers = new double[docIds.size()];
        for (int i = 0; i < docIds.size(); i++) {
            String docId = docIds.get(i);
            Pair<MultiLabel, Double> docInfo = map.get(docId);

            MultiLabel pre = docInfo.getFirst();
            MultiLabel lab = new MultiLabel(groundTruth.get(docId),labelTranslator);

            double truth = 0;
            if (pre.equals(lab)) {
                truth = 1;
            }

            double confidence = map.get(docId).getSecond();
            locations[i] = confidence;
            numbers[i] = truth;

        }

        IsotonicRegression isotonicRegression = new IsotonicRegression(locations, numbers);

        return isotonicRegression;

    }

    private static void generateReport(Map<String,Pair<MultiLabel,Double>> map,Config config,String dataSetFolder,LabelTranslator labelTranslator,Map<String,String> groundTruth,List<Map<String,Pair<Double,Integer>>> confideceRankLists,IsotonicRegression isotonicRegression)throws Exception{

        List<String> modelPaths = config.getStrings("modelPaths");
        List<String> docIds = ReportUtils.getDocIds(Paths.get(modelPaths.get(0),"predictions",dataSetFolder+"_reports","report.csv").toString());

        StringBuilder sb = new StringBuilder();
        sb.append("doc_id").append("\t").append("prediction").append("\t").append("prediction_type").append("\t")
                .append("confidence").append("\t").append("truth").append("\t").append("ground_truth").append("\t")
                .append("precision").append("\t").append("recall").append("\t").append("F1").append("\t")
                .append("gb-tenant_confidence").append("\t").append("gb-tenant_rank").append("\t").append("lr-tenant_confidence").append("\t")
                .append("lr-tenant_rank").append("\t").append("gb-common_confidence").append("\t").append("gb-common_rank").append("\t")
                .append("lr-common_confidence").append("\t").append("lr-common_rank").append("\n");



        for (int i = 0; i < docIds.size(); i++) {
            String docId = docIds.get(i);<commit_msg>using model names in config for CombSum report<commit_after>package edu.neu.ccs.pyramid.application;

import edu.neu.ccs.pyramid.calibration.CTAT;
import edu.neu.ccs.pyramid.calibration.CTFT;
import edu.neu.ccs.pyramid.configuration.Config;
import edu.neu.ccs.pyramid.dataset.*;
import edu.neu.ccs.pyramid.eval.FMeasure;
import edu.neu.ccs.pyramid.eval.Precision;
import edu.neu.ccs.pyramid.eval.Recall;
import edu.neu.ccs.pyramid.regression.IsotonicRegression;
import edu.neu.ccs.pyramid.util.FileUtil;
import edu.neu.ccs.pyramid.util.Pair;
import edu.neu.ccs.pyramid.util.ReportUtils;
import edu.neu.ccs.pyramid.util.Serialization;
import org.apache.commons.io.FileUtils;
import sun.rmi.runtime.Log;

import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AppCombSUM {


    public static void main(String[] args)throws Exception{
        if (args.length !=1){
            throw new IllegalArgumentException("Please specify a properties file.");
        }

        Config config = new Config(args[0]);
        Logger logger = Logger.getAnonymousLogger();
        String logFile = config.getString("output.log");
        FileHandler fileHandler = null;
        if (!logFile.isEmpty()){
            new File(logFile).getParentFile().mkdirs();
            //todo should append?
            fileHandler = new FileHandler(logFile, true);
            Formatter formatter = new SimpleFormatter();
            fileHandler.setFormatter(formatter);
            logger.addHandler(fileHandler);
            logger.setUseParentHandlers(false);
        }

        logger.info(config.toString());


        File output = new File(config.getString("output.folder"));
        output.mkdirs();



        if (config.getBoolean("calibrate")){
            calibrate(config,logger);
        }


        if (config.getBoolean("validate")){
            report(config,config.getString("validFolder"));
        }


        if(config.getBoolean("tuneThreshold")){
            tuneThreshold(config,logger);

        }

        if (config.getBoolean("test")){
            report(config,config.getString("testFolder"));
            testAutomation(config,logger);
        }


        if (fileHandler!=null){
            fileHandler.close();
        }

    }


    private static IsotonicRegression trainIsoRegression(Map<String,Pair<MultiLabel,Double>> map,Config config,LabelTranslator labelTranslator,Map<String,String> groundTruth)throws Exception {
        List<String> modelPaths = config.getStrings("modelPaths");
        String calibFolder = config.getString("calibFolder");
        List<String> docIds = ReportUtils.getDocIds(Paths.get(modelPaths.get(0),"predictions",calibFolder+"_reports","report.csv").toString());
        double[] locations = new double[docIds.size()];
        double[] numbers = new double[docIds.size()];
        for (int i = 0; i < docIds.size(); i++) {
            String docId = docIds.get(i);
            Pair<MultiLabel, Double> docInfo = map.get(docId);

            MultiLabel pre = docInfo.getFirst();
            MultiLabel lab = new MultiLabel(groundTruth.get(docId),labelTranslator);

            double truth = 0;
            if (pre.equals(lab)) {
                truth = 1;
            }

            double confidence = map.get(docId).getSecond();
            locations[i] = confidence;
            numbers[i] = truth;

        }

        IsotonicRegression isotonicRegression = new IsotonicRegression(locations, numbers);

        return isotonicRegression;

    }

    private static void generateReport(Map<String,Pair<MultiLabel,Double>> map,Config config,String dataSetFolder,LabelTranslator labelTranslator,Map<String,String> groundTruth,List<Map<String,Pair<Double,Integer>>> confideceRankLists,IsotonicRegression isotonicRegression)throws Exception{

        List<String> modelNames = config.getStrings("modelNames");
        List<String> modelPaths = config.getStrings("modelPaths");
        List<String> docIds = ReportUtils.getDocIds(Paths.get(modelPaths.get(0),"predictions",dataSetFolder+"_reports","report.csv").toString());

        StringBuilder sb = new StringBuilder();
        sb.append("doc_id").append("\t").append("prediction").append("\t").append("prediction_type").append("\t")
                .append("confidence").append("\t").append("truth").append("\t").append("ground_truth").append("\t")
                .append("precision").append("\t").append("recall").append("\t").append("F1").append("\t");
        for(int i = 0; i < modelNames.size(); i++){
            sb.append(modelNames.get(i)).append("_confidence").append("\t").append(modelNames.get(i)).append("_rank").append("\t");
        }
        sb.append("\n");



        for (int i = 0; i < docIds.size(); i++) {
            String docId = docIds.get(i);
{'fraction_non_alphanumeric': 0.14231763068972372, 'fraction_numerical': 0.0018882925859670045, 'mean_word_length': 3.1720563847429517, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '678637', 'n_tokens_mistral': 3031, 'n_tokens_neox': 2911, 'n_words': 464}