/*******************************************************************************
 * Copyright 2016
 * Language Technology Lab
 * University of Duisburg-Essen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.unidue.ltl.evaluation.examples;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import de.unidue.ltl.evaluation.Evaluation;
import de.unidue.ltl.evaluation.EvaluationResult;
import de.unidue.ltl.evaluation.io.TextReader;
import de.unidue.ltl.evaluation.measure.EvaluationMeasure;
import de.unidue.ltl.evaluation.measure.util.CategorialMeasuresUtil;

public class CalculateMeasuresFromGold2PredictedFile {

	//labelsMapping = {'none': 0, 'favor': 1, 'against': 2}
	public static void main(String[] args) throws IOException {
//		File folder= new File("/Users/michael/git/ucsm_git/stance_lstm/result/");
		File folder= new File("/Users/michael/git/ucsm_git/stance_lstm/result/cv/");
		Map<String,Double> resultsFSemeval= new HashMap<>();
		Map<String,Double> resultsF_micro= new HashMap<>();
		for(File file:folder.listFiles()){
			if(file.isDirectory())continue;
			Evaluation<String> evaluation= TextReader.fromTabSeparated(file);
			Map<String, EvaluationResult> results = CategorialMeasuresUtil.computeCategorialResults(evaluation.getEntries());
			double f_favor=0;
			double f_against=0;
			double f_micro=0;
			for(String measure:results.keySet()){
//				System.out.println(measure+" "+results.get(measure).getResult());
				if(measure.equals("Fscore_1")){
					f_favor=results.get(measure).getResult();
				}
				if(measure.equals("Fscore_2")){
					f_against=results.get(measure).getResult();
				}
				if(measure.equals("Fscore_MICRO")){
					f_micro=results.get(measure).getResult();
				}
				resultsF_micro.put(file.getName(), f_micro);
				resultsFSemeval.put(file.getName(),(f_against+f_favor)/2);
			}
		}
		System.out.println("##### SEMEVAL #####");
		for(String file:resultsFSemeval.keySet()){
			System.out.println(file+" : "+resultsFSemeval.get(file));
		}
		System.out.println("##### F1 #####");
		for(String file:resultsF_micro.keySet()){
			System.out.println(file+" : "+resultsF_micro.get(file));
		}

	}

}

@@ -1260,65 +1260,8 @@
  %7B%0A%0A
-%09//labelsMapping = %7B'none': 0, 'favor': 1, 'against': 2%7D%0A
 %09pub
@@ -1321,416 +1321,144 @@
 n %7B%0A
-//%09%09File folder= new File(%22/Users/michael/git/ucsm_git/stance_lstm/result/%22);%0A%09%09File folder= new File(%22/Users/michael/git/ucsm_git/stance_l
+%09%09Evaluation%3CString%3E evaluation = TextReader%0A%09%09%09%09.fromTabSeparated(new File(%22src/te
 st
-m
 /res
-ult/cv/%22);%0A%09%09Map%3CString,Double%3E resultsFSemeval= new HashMap%3C%3E();%0A%09%09Map%3CString,Double%3E resultsF_micro= new HashMap%3C%3E();%0A%09%09for(File file:folder.listFiles())%7B%0A%09%09%09if(file.isDirectory())continue;%0A%09%09%09Evaluation%3CString%3E evaluation= TextReader.fromTabSeparated(file
+ources/io/tab-separated_gold2predicted.txt%22)
 );%0A
-%09
 %09%09Ma
@@ -1517,16 +1517,21 @@
 uresUtil
+%0A%09%09%09%09
 .compute
@@ -1580,77 +1580,12 @@
 ;%0A%09%09
-%09double f_favor=0;%0A%09%09%09double f_against=0;%0A%09%09%09double f_micro=0;%0A%09%09%09
 for
+ 
 (Str
@@ -1595,17 +1595,19 @@
  measure
-:
+ : 
 results.
@@ -1619,16 +1619,14 @@
 t())
+ 
 %7B%0A
-//
 %09%09%09
-%09
 Syst
@@ -1651,13 +1651,17 @@
 sure
-+%22 %22+
+ + %22 %22 + 
 resu
@@ -1697,703 +1697,9 @@
 ;%0A%09%09
-%09%09if(measure.equals(%22Fscore_1%22))%7B%0A%09%09%09%09%09f_favor=results.get(measure).getResult();%0A%09%09%09%09%7D%0A%09%09%09%09if(measure.equals(%22Fscore_2%22))%7B%0A%09%09%09%09%09f_against=results.get(measure).getResult();%0A%09%09%09%09%7D%0A%09%09%09%09if(measure.equals(%22Fscore_MICRO%22))%7B%0A%09%09%09%09%09f_micro=results.get(measure).getResult();%0A%09%09%09%09%7D%0A%09%09%09%09resultsF_micro.put(file.getName(), f_micro);%0A%09%09%09%09resultsFSemeval.put(file.getName(),(f_against+f_favor)/2);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09System.out.println(%22##### SEMEVAL #####%22);%0A%09%09for(String file:resultsFSemeval.keySet())%7B%0A%09%09%09System.out.println(file+%22 : %22+resultsFSemeval.get(file));%0A%09%09%7D%0A%09%09System.out.println(%22##### F1 #####%22);%0A%09%09for(String file:resultsF_micro.keySet())%7B%0A%09%09%09System.out.println(file+%22 : %22+resultsF_micro.get(file));%0A%09%09%7D%0A
+%7D
 %0A%09%7D%0A

version fix