001/*
002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.tribuo.evaluation;
018
019import org.tribuo.Output;
020
021/**
022 * Renders an {@link Evaluation} into a String.
023 * <p>
024 * For example, an implementation might produce
025 *
026 * @param <T> type of output
027 * @param <E> type of evaluation
028 */
029@FunctionalInterface
030public interface EvaluationRenderer<T extends Output<T>, E extends Evaluation<T>> {
031
032    /**
033     * Convert the evaluation to a string. For example:
034     *
035     * <pre>
036     *     EvaluationRenderer&lt;Label, LabelEvaluation&gt; renderer = (LabelEvaluation eval) -&gt; {
037     *         StringBuilder sb = new StringBuilder();
038     *         sb.append(String.format("macro F1: %.2f", eval.macroAveragedF1()));
039     *         sb.append(String.format("micro F1: %.2f", eval.microAveragedF1()));
040     *         return sb.toString();
041     *     }
042     *
043     *     LabelEvaluation evaluation = ...
044     *     System.out.println(renderer.apply(evaluation));
045     * </pre>
046     *
047     * @param evaluation The evaluation to render.
048     * @return The renderer's representation of the evaluation as a String.
049     */
050    String apply(E evaluation);
051
052}