1   package eu.fbk.dkm.pikes.raid;
2   
3   import eu.fbk.utils.core.CommandLine;
4   import org.slf4j.LoggerFactory;
5   
6   import java.io.BufferedReader;
7   import java.io.File;
8   import java.io.FileReader;
9   
10  /**
11   * Created by alessio on 08/05/15.
12   */
13  
14  public class SimpleEvaluation {
15  
16  	private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SimpleEvaluation.class);
17  
18  	public static void main(String[] args) {
19  		try {
20  			final CommandLine cmd = CommandLine
21  					.parser()
22  					.withName("yamcha-evaluator")
23  					.withHeader("Evaluate YAMCHA classification")
24  					.withOption("i", "input-file", "the test file annotated", "FILE", CommandLine.Type.FILE_EXISTING, true, false, true)
25  //					.withOption("g", "gold", "gold column (starting from 0)", "NUM", CommandLine.Type.POSITIVE_INTEGER, true, false, true)
26  //					.withOption("t", "test", "test column (starting from 0)", "NUM", CommandLine.Type.POSITIVE_INTEGER, true, false, true)
27  					.withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);
28  
29  			File testFile = cmd.getOptionValue("i", File.class);
30  			BufferedReader reader = new BufferedReader(new FileReader(testFile));
31  
32  			String line;
33  
34  			int total = 0;
35  			int correct = 0;
36  
37  			while ((line = reader.readLine()) != null) {
38  
39  				String[] parts = line.split("\\s");
40  				if (parts.length < 2) {
41  					continue;
42  				}
43  
44  				int testCol = parts.length - 1;
45  				int goldCol = parts.length - 2;
46  
47  				total++;
48  				if (parts[testCol].equals(parts[goldCol])) {
49  					correct++;
50  				}
51  			}
52  
53  			reader.close();
54  
55  			System.out.println("Results: " + correct + "/" + total);
56  		} catch (final Throwable ex) {
57  			CommandLine.fail(ex);
58  		}
59  
60  	}
61  }