package org.grobid.trainer;

public final class LabelStat {
    private int falsePositive;
    private int falseNegative;
    private int observed;
    private int expected;

    public void incrementFalseNegative() { 
        this.incrementFalseNegative(1); 
    }
    
    public void incrementFalsePositive() { 
        this.incrementFalsePositive(1); 
    }
    
    public void incrementObserved() { 
        this.incrementObserved(1);
    }
    
    public void incrementExpected() { 
        this.incrementExpected(1); 
    }

    public void incrementFalseNegative(int count) { 
        this.falseNegative += count; 
    }
    
    public void incrementFalsePositive(int count) { 
        this.falsePositive += count; 
    }
    
    public void incrementObserved(int count) { 
        this.observed += count; 
    }

    public void incrementExpected(int count) { 
        this.expected += count; 
    }

    public int getExpected() {
        return this.expected;
    }
    public int getFalseNegative() {
        return this.falseNegative;
    }
    public int getFalsePositive() {
        return this.falsePositive;
    }
    public int getObserved() {
        return this.observed;
    }

    public void setFalsePositive(int falsePositive) {
        this.falsePositive = falsePositive;
    }

    public void setFalseNegative(int falseNegative) {
        this.falseNegative = falseNegative;
    }

    public void setObserved(int observed) {
        this.observed = observed;
    }

    public void setExpected(int expected) {
        this.expected = expected;
    }

    public static LabelStat create() {
        return new LabelStat();
    }

    public double getPrecision() {
        return (double) (observed - (falsePositive + falseNegative) ) / (observed);
    }

    public double getRecall() {
        return (double) (observed - (falsePositive + falseNegative) ) / (expected);
    }

    public double getF1Score() {
        double precision = getPrecision();
        double recall = getRecall();

        return (2 * precision * recall) / (precision + recall);
    }
}

@@ -1701,122 +1701,402 @@
     
-return (double) (observed - (falsePositive + falseNegative) ) / (observed);%0A    %7D%0A%0A    public double getRecall() %7B
+if (observed == 0.0) %7B%0A            return 0.0;%0A        %7D%0A        if ((falsePositive + falseNegative) %3E= observed)%0A            return 0.0;%0A        return (double) (observed - (falsePositive + falseNegative) ) / (observed);%0A    %7D%0A%0A    public double getRecall() %7B%0A        if (expected == 0.0)%0A            return 0.0;%0A        if ((falsePositive + falseNegative) %3E= observed)%0A            return 0.0;
 %0A   
@@ -2297,16 +2297,92 @@
 all();%0A%0A
+        if ( (precision == 0) && (recall == 0.0) )%0A            return 0.0;%0A%0A
         
@@ -2390,16 +2390,18 @@
 eturn (2
+.0
  * preci
@@ -2444,11 +2444,399 @@
 );%0A    %7D
+%0A%0A    @Override %0A    public String toString() %7B%0A        StringBuilder builder = new StringBuilder();%0A        builder%0A            .append(%22falsePositive: %22).append(falsePositive)%0A            .append(%22; falseNegative: %22).append(falseNegative)%0A            .append(%22; observed: %22).append(observed)%0A            .append(%22; expected: %22).append(expected);%0A        return builder.toString();%0A    %7D
 %0A%7D%0A

Improve evaluation structures