Skip to content

Commit

Permalink
Merge pull request #452 from dice-group/dev/arjanoop/contingency_matr…
Browse files Browse the repository at this point in the history
…ix_extension

Contingency Matrix Extension for storing related macros
  • Loading branch information
MichaelRoeder authored Jul 5, 2024
2 parents efc2781 + 31996b4 commit 331498f
Show file tree
Hide file tree
Showing 35 changed files with 326 additions and 134 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ gerbil_data
google*.html
export
datadump.nt
indexdbpedia_en_2014
indexdbpedia_en_2014
.idea
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected void increaseErrorCount() throws GerbilException {
}

@Override
public void evaluate(List<List<Marking>> annotatorResults, List<List<Marking>> goldStandard,
public void evaluate(List<Document> instances, List<List<Marking>> annotatorResults, List<List<Marking>> goldStandard,
EvaluationResultContainer results) {
results.addResult(new IntEvaluationResult(ERROR_COUNT_RESULT_NAME, errorCount));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void reset() {
}

@Override
public void evaluate(List<List<Marking>> annotatorResults, List<List<Marking>> goldStandard,
public void evaluate(List<Document> instances, List<List<Marking>> annotatorResults, List<List<Marking>> goldStandard,
EvaluationResultContainer results) {
if (callCount > 0) {
results.addResult(new DoubleEvaluationResult(AVG_TIME_RESULT_NAME, getAverageRuntime()));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/aksw/gerbil/database/ExperimentDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.aksw.gerbil.datatypes.ErrorTypes;
import org.aksw.gerbil.datatypes.ExerimentTaskBlobResultType;
import org.aksw.gerbil.datatypes.ExperimentTaskResult;
import org.aksw.gerbil.evaluate.ObjectEvaluationResult;
import org.aksw.gerbil.evaluate.AggregatedContingencyMetricsReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
Expand Down Expand Up @@ -211,8 +211,8 @@ public void setExperimentTaskResult(int experimentTaskId, ExperimentTaskResult r
parameters.addValue("lastChanged", new java.sql.Timestamp(result.timestamp));

this.template.update(SET_EXPERIMENT_TASK_RESULT, parameters);
if(result.hasContingencyMatrix()){
insertContingencyMatrix(experimentTaskId, result.contingencyMatrix);
if(result.hasContingencyMetricsReport()){
insertContingencyMetricsReport(experimentTaskId, result.aggregatedContingencyMetricsReport);
}
if (result.hasAdditionalResults()) {
for (int i = 0; i < result.additionalResults.allocated.length; ++i) {
Expand Down Expand Up @@ -502,11 +502,11 @@ public Integer countExperiments() {
return result.get(0);
}

public void insertContingencyMatrix(int taskId, ObjectEvaluationResult contingencyMatrix){
public void insertContingencyMetricsReport(int taskId, AggregatedContingencyMetricsReport aggregatedContingencyMetricsReport){
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("taskId", taskId);
parameters.addValue("resultId", ExerimentTaskBlobResultType.getResultId(contingencyMatrix.getName()));
parameters.addValue("resultValue", gson.toJson(contingencyMatrix).getBytes());
parameters.addValue("resultId", ExerimentTaskBlobResultType.getResultId(aggregatedContingencyMetricsReport.getName()));
parameters.addValue("resultValue", gson.toJson(aggregatedContingencyMetricsReport.getValue()).getBytes());
this.template.update(INSERT_ADDITIONAL_BLOB_RESULTS, parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;

import org.aksw.gerbil.database.ExperimentDAO;
import org.aksw.gerbil.evaluate.ObjectEvaluationResult;
import org.aksw.gerbil.evaluate.AggregatedContingencyMetricsReport;
import org.aksw.gerbil.matching.Matching;

import com.carrotsearch.hppc.IntDoubleOpenHashMap;
Expand All @@ -38,7 +38,7 @@ public class ExperimentTaskResult {
public static final int MACRO_RECALL_INDEX = 5;

public double results[];
public ObjectEvaluationResult contingencyMatrix;
public AggregatedContingencyMetricsReport aggregatedContingencyMetricsReport;
public int state;
public int errorCount;
public long timestamp;
Expand Down Expand Up @@ -361,15 +361,15 @@ public int getNumberOfSubTasks() {
}
}

public ObjectEvaluationResult getContingencyMatrix() {
return contingencyMatrix;
public AggregatedContingencyMetricsReport getContingencyMetricsReport() {
return aggregatedContingencyMetricsReport;
}

public void setContingencyMatrix(ObjectEvaluationResult contingencyMatrix) {
this.contingencyMatrix = contingencyMatrix;
public void setContingencyMetricsReport(AggregatedContingencyMetricsReport aggregatedContingencyMetricsReport) {
this.aggregatedContingencyMetricsReport = aggregatedContingencyMetricsReport;
}

public boolean hasContingencyMatrix() {
return contingencyMatrix != null;
public boolean hasContingencyMetricsReport() {
return aggregatedContingencyMetricsReport !=null && aggregatedContingencyMetricsReport.getValue()!=null && !(aggregatedContingencyMetricsReport.getValue().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;

import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.transfer.nif.Marking;

public abstract class AbstractTypeTransformingEvaluatorDecorator<U extends Marking, V extends Marking>
Expand All @@ -36,9 +37,9 @@ public Evaluator<V> getDecorated() {
}

@Override
public void evaluate(List<List<U>> annotatorResults, List<List<U>> goldStandard,
EvaluationResultContainer results) {
evaluator.evaluate(changeListType(annotatorResults), changeListType(goldStandard), results);
public void evaluate(List<Document> instances, List<List<U>> annotatorResults, List<List<U>> goldStandard,
EvaluationResultContainer results) {
evaluator.evaluate(instances, changeListType(annotatorResults), changeListType(goldStandard), results);
}

protected List<List<V>> changeListType(List<List<U>> markings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Represents an aggregate report of evaluation results containing multiple extended contingency metrics.
* This file is part of General Entity Annotator Benchmark.
*
* General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.evaluate;

import java.util.ArrayList;
import java.util.List;

/**
* Represents an aggregate report of evaluation results containing multiple extended contingency metrics.
*/
public class AggregatedContingencyMetricsReport implements EvaluationResult{

/** The name of the evaluation result. */
private String name;

/** The list of extended contingency metrics comprising the evaluation result. */
private List<ExtendedContingencyMetrics> value;

/**
* Constructs an instance of AggregatedContingencyMetricsReport with the given name.
*
* @param name The name of the evaluation result.
*/
public AggregatedContingencyMetricsReport(String name) {
this.name = name;
this.value = new ArrayList<ExtendedContingencyMetrics>();
}

/**
* Constructs an instance of AggregatedContingencyMetricsReport with the given name and initial set of extended metrics.
*
* @param name The name of the evaluation result.
* @param value An array of ExtendedContingencyMetrics representing the initial set of extended metrics.
*/
public AggregatedContingencyMetricsReport(String name, ExtendedContingencyMetrics[] value) {
this(name);
this.addMetrics(value);
}

/**
* Retrieves the name of the evaluation result.
* @return The name of the evaluation result.
*/
@Override
public String getName() {
return name;
}

/**
* Retrieves the list of extended metrics comprising the evaluation result.
* @return The list of extended metrics.
*/
@Override
public List<ExtendedContingencyMetrics> getValue() {
return value;
}

/**
* Adds one or more extended metrics to the evaluation result.
* @param metrics One or more ExtendedContingencyMetrics objects to be added to the evaluation result.
*/
public void addMetrics(ExtendedContingencyMetrics... metrics) {
for(ExtendedContingencyMetrics metric : metrics){
this.value.add(metric);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/aksw/gerbil/evaluate/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import java.util.List;

import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.transfer.nif.Marking;

public interface Evaluator<T extends Marking> {

public void evaluate(List<List<T>> annotatorResults, List<List<T>> goldStandard, EvaluationResultContainer results);
public void evaluate(List<Document> instances, List<List<T>> annotatorResults, List<List<T>> goldStandard, EvaluationResultContainer results);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Represents extended evaluation metrics of an entity based on a contingency matrix.
* This file is part of General Entity Annotator Benchmark.
*
* General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.evaluate;

import org.aksw.gerbil.matching.EvaluationCounts;

/**
* Represents extended contingency metrics of an entity procured from experiment.
*/
public class ExtendedContingencyMetrics {

/** The identifier of the entity. */
private String id;

/** Evaluation counts of Contingency Matrix for the entity. */
private EvaluationCounts count;

/** The precision score of the entity. */
private double precision;

/** The recall score of the entity. */
private double recall;

/** The F1 score of the entity. */
private double f1Score;

/**
* Constructs an instance of ExtendedContingencyMetrics.
*
* @param id The identifier of the entity.
* @param count Evaluation counts for the entity.
* @param precision The precision score of the entity.
* @param recall The recall score of the entity.
* @param f1Score The F1 score of the entity.
*/
public ExtendedContingencyMetrics(String id, EvaluationCounts count, double precision, double recall, double f1Score) {
this.id = id;
this.count = count;
this.precision = precision;
this.recall = recall;
this.f1Score = f1Score;
}

/**
* Retrieves the identifier of the entity.
* @return The identifier of the entity.
*/
public String getId() {
return id;
}

/**
* Retrieves the evaluation counts for the entity.
* @return Evaluation counts for the entity.
*/
public EvaluationCounts getCount() {
return count;
}

/**
* Retrieves the precision score of the entity.
* @return The precision score of the entity.
*/
public double getPrecision() {
return precision;
}

/**
* Retrieves the recall score of the entity.
* @return The recall score of the entity.
*/
public double getRecall() {
return recall;
}

/**
* Retrieves the F1 score of the entity.
* @return The F1 score of the entity.
*/
public double getF1Score() {
return f1Score;
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/aksw/gerbil/evaluate/SubTaskEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;

import org.aksw.gerbil.datatypes.ExperimentTaskConfiguration;
import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.transfer.nif.Marking;

public class SubTaskEvaluator<T extends Marking> implements Evaluator<T> {
Expand All @@ -40,10 +41,10 @@ public SubTaskEvaluator(ExperimentTaskConfiguration configuration, Evaluator<T>

@SuppressWarnings("unchecked")
@Override
public void evaluate(List<List<T>> annotatorResults, List<List<T>> goldStandard, EvaluationResultContainer results) {
public void evaluate(List<Document> instances, List<List<T>> annotatorResults, List<List<T>> goldStandard, EvaluationResultContainer results) {
SubTaskResult subTaskResults = new SubTaskResult(configuration);
for (Evaluator<? extends Marking> e : evaluators) {
((Evaluator<T>) e).evaluate(annotatorResults, goldStandard, subTaskResults);
((Evaluator<T>) e).evaluate(instances, annotatorResults, goldStandard, subTaskResults);
if (subTaskResults.getResults().size() > 0) {
results.addResult(subTaskResults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.aksw.gerbil.matching.MatchingsCounter;
import org.aksw.gerbil.matching.scored.ScoredEvaluationCountsArray;
import org.aksw.gerbil.matching.scored.ScoredMatchingsCounterImpl;
import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.utils.filter.MarkingClassBasedMarkingFilter;
import org.aksw.gerbil.utils.filter.MarkingFilter;

Expand Down Expand Up @@ -57,8 +58,8 @@ public ClassConsideringFMeasureCalculator(MatchingsCounter<T> matchingsCounter,
}

@Override
public void evaluate(List<List<T>> annotatorResults, List<List<T>> goldStandard,
EvaluationResultContainer results) {
public void evaluate(List<Document> instances, List<List<T>> annotatorResults, List<List<T>> goldStandard,
EvaluationResultContainer results) {
// the super class performs the matching counter calls
ScoredEvaluationCountsArray counts = generateMatchingCounts(annotatorResults, goldStandard);
if ((counts.truePositiveSums.length > 0) && (counts.falseNegativeSums.length > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.aksw.gerbil.matching.scored.ScoredEvaluationCountsArray;
import org.aksw.gerbil.matching.scored.ScoredMatchingsCounter;
import org.aksw.gerbil.matching.scored.ScoredMatchingsCounterImpl;
import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.transfer.nif.Marking;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -48,8 +49,8 @@ public ConfidenceBasedFMeasureCalculator(MatchingsCounter<T> matchingsCounter) {
}

@Override
public void evaluate(List<List<T>> annotatorResults, List<List<T>> goldStandard,
EvaluationResultContainer results) {
public void evaluate(List<Document> instances, List<List<T>> annotatorResults, List<List<T>> goldStandard,
EvaluationResultContainer results) {
ScoredEvaluationCountsArray counts = generateMatchingCounts(annotatorResults, goldStandard);
if ((counts.truePositiveSums.length > 0) && (counts.falseNegativeSums.length > 0)
&& (counts.falsePositiveSums.length > 0)) {
Expand Down
Loading

0 comments on commit 331498f

Please sign in to comment.