// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AuthorAgeSample.java
// public class AuthorAgeSample implements Serializable{
// 	private static final long serialVersionUID = 5374409234122582256L;
// 	
// 	public static final String FORMAT_NAME = "authorage";
// 	
// 	private final String ageCategory;
//     
//     private final List<String> text;    
//     
//     public AuthorAgeSample(String category, String text[]) {
// 	if (category == null) {
// 	    throw new IllegalArgumentException("Age cannot be null");
// 	}
// 	if (text == null) {
// 	    throw new IllegalArgumentException("Text cannot be null");
// 	}
// 	
// 	this.ageCategory = category;
// 	
// 	this.text = Collections
// 	    .unmodifiableList(new ArrayList<String>(Arrays.asList(text)));
//     }
// 
// 
//     public AuthorAgeSample(Integer age, String text[]) {
// 	if (age == null) {
// 	    throw new IllegalArgumentException("Age cannot be null");
// 	}
// 	if (text == null) {
// 	    throw new IllegalArgumentException("Text cannot be null");
// 	}
// 	
// 	if (age < 18) {
// 	    ageCategory = "xx-18";
// 	}
// 	else if (age >= 18 && age <= 24) {
// 	    ageCategory = "18-24";
// 	}
// 	else if (age >= 25 && age <= 34) {
// 	    ageCategory = "25-34";
// 	}
// 	else if (age >= 35 && age <= 49) {
// 	    ageCategory = "35-49";
// 	}
// 	else if (age >= 50 && age <= 64) {
// 	    ageCategory = "50-64";
// 	}
// 	else { // (age > 65)
// 	    ageCategory = "65-xx";
// 	}
// 	
// 	this.text = Collections
// 	    .unmodifiableList(new ArrayList<String>(Arrays.asList(text)));
//     }
//     
//     public String getCategory() {
// 	return this.ageCategory;
//     }
// 
//     public String[] getText() {
// 	return this.text.toArray(new String[this.text.size()]);
//     }
// 
//     @Override
//     public String toString() {
// 	StringBuilder sampleString = new StringBuilder();
// 
// 	sampleString.append(ageCategory).append('\t');
// 
// 	for (String s : text) {
// 	    sampleString.append(s).append(' ');
// 	}
// 
// 	if (sampleString.length() > 0) {
// 	    // remove last space
// 	    sampleString.setLength(sampleString.length() - 1);
// 	}
// 
// 	return sampleString.toString();
//     }
//     
//     
// }


import java.io.OutputStream;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import opennlp.tools.authorage.AgeClassifyEvaluationMonitor;
import opennlp.tools.authorage.AuthorAgeSample;
import opennlp.tools.util.Span;
import opennlp.tools.util.eval.FMeasure;
import opennlp.tools.util.eval.Mean;
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 edu.usc.irds.agepredictor.cmdline.authorage;



/**
 * Generates a detailed report for the Age Classifier.
 * <p>
 * It is possible to use it from an API and access the statistics using the
 * provided getters
 *
 */

public class AgeClassifyFineGrainedReportListener implements AgeClassifyEvaluationMonitor {

    private final PrintStream printStream;
    private final Stats stats = new Stats();

    private static final char[] alpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
					  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
					  'w', 'x', 'y', 'z' };

    /**
     * Creates a listener that will print to {@link System#err}
     */
    public AgeClassifyFineGrainedReportListener() {
	this(System.err);
    }

    /**
     * Creates a listener that prints to a given {@link OutputStream}
     */
    public AgeClassifyFineGrainedReportListener(OutputStream outputStream) {
	this.printStream = new PrintStream(outputStream);
    }

    // methods inherited from EvaluationMonitor

// Path: age-predictor-opennlp/src/main/java/opennlp/tools/authorage/AuthorAgeSample.java
// public class AuthorAgeSample implements Serializable{
// 	private static final long serialVersionUID = 5374409234122582256L;
// 	
// 	public static final String FORMAT_NAME = "authorage";
// 	
// 	private final String ageCategory;
//     
//     private final List<String> text;    
//     
//     public AuthorAgeSample(String category, String text[]) {
// 	if (category == null) {
// 	    throw new IllegalArgumentException("Age cannot be null");
// 	}
// 	if (text == null) {
// 	    throw new IllegalArgumentException("Text cannot be null");
// 	}
// 	
// 	this.ageCategory = category;
// 	
// 	this.text = Collections
// 	    .unmodifiableList(new ArrayList<String>(Arrays.asList(text)));
//     }
// 
// 
//     public AuthorAgeSample(Integer age, String text[]) {
// 	if (age == null) {
// 	    throw new IllegalArgumentException("Age cannot be null");
// 	}
// 	if (text == null) {
// 	    throw new IllegalArgumentException("Text cannot be null");
// 	}
// 	
// 	if (age < 18) {
// 	    ageCategory = "xx-18";
// 	}
// 	else if (age >= 18 && age <= 24) {
// 	    ageCategory = "18-24";
// 	}
// 	else if (age >= 25 && age <= 34) {
// 	    ageCategory = "25-34";
// 	}
// 	else if (age >= 35 && age <= 49) {
// 	    ageCategory = "35-49";
// 	}
// 	else if (age >= 50 && age <= 64) {
// 	    ageCategory = "50-64";
// 	}
// 	else { // (age > 65)
// 	    ageCategory = "65-xx";
// 	}
// 	
// 	this.text = Collections
// 	    .unmodifiableList(new ArrayList<String>(Arrays.asList(text)));
//     }
//     
//     public String getCategory() {
// 	return this.ageCategory;
//     }
// 
//     public String[] getText() {
// 	return this.text.toArray(new String[this.text.size()]);
//     }
// 
//     @Override
//     public String toString() {
// 	StringBuilder sampleString = new StringBuilder();
// 
// 	sampleString.append(ageCategory).append('\t');
// 
// 	for (String s : text) {
// 	    sampleString.append(s).append(' ');
// 	}
// 
// 	if (sampleString.length() > 0) {
// 	    // remove last space
// 	    sampleString.setLength(sampleString.length() - 1);
// 	}
// 
// 	return sampleString.toString();
//     }
//     
//     
// }


// Path: age-predictor-cli/src/main/java/edu/usc/irds/agepredictor/cmdline/authorage/AgeClassifyFineGrainedReportListener.java
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import opennlp.tools.authorage.AgeClassifyEvaluationMonitor;
import opennlp.tools.authorage.AuthorAgeSample;
import opennlp.tools.util.Span;
import opennlp.tools.util.eval.FMeasure;
import opennlp.tools.util.eval.Mean;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 edu.usc.irds.agepredictor.cmdline.authorage;



/**
 * Generates a detailed report for the Age Classifier.
 * <p>
 * It is possible to use it from an API and access the statistics using the
 * provided getters
 *
 */

public class AgeClassifyFineGrainedReportListener implements AgeClassifyEvaluationMonitor {

    private final PrintStream printStream;
    private final Stats stats = new Stats();

    private static final char[] alpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
					  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
					  'w', 'x', 'y', 'z' };

    /**
     * Creates a listener that will print to {@link System#err}
     */
    public AgeClassifyFineGrainedReportListener() {
	this(System.err);
    }

    /**
     * Creates a listener that prints to a given {@link OutputStream}
     */
    public AgeClassifyFineGrainedReportListener(OutputStream outputStream) {
	this.printStream = new PrintStream(outputStream);
    }

    // methods inherited from EvaluationMonitor

    public void missclassified(AuthorAgeSample reference, AuthorAgeSample prediction) {