Search in sources :

Example 1 with ConfusionMatrix

use of edu.stanford.nlp.util.ConfusionMatrix in project CoreNLP by stanfordnlp.

the class ConfusionMatrixTSV method main.

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.printf("Usage: java %s answers_file%n", ConfusionMatrix.class.getName());
        System.exit(-1);
    }
    try {
        ConfusionMatrix<String> cm = new ConfusionMatrix<>();
        String answersFile = args[0];
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(answersFile), "UTF-8"));
        String line = br.readLine();
        for (; line != null; line = br.readLine()) {
            String[] tokens = line.split("\\s");
            if (tokens.length != 3) {
                System.err.printf("ignoring bad line");
                continue;
            //System.exit(-1);
            }
            cm.add(tokens[2], tokens[1]);
        }
        System.out.println(cm.toString());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ConfusionMatrix(edu.stanford.nlp.util.ConfusionMatrix) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

ConfusionMatrix (edu.stanford.nlp.util.ConfusionMatrix)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1