From 2e40792808762f033c9d499899a5e5abb86dbe0c Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@etu.univ-amu.fr>
Date: Fri, 14 Dec 2018 14:49:39 +0100
Subject: [PATCH] Added more info to errors evaluation

---
 error_correction/include/Error.hpp |  4 ++++
 error_correction/src/Error.cpp     | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/error_correction/include/Error.hpp b/error_correction/include/Error.hpp
index ba4bb0e..4a49d6b 100644
--- a/error_correction/include/Error.hpp
+++ b/error_correction/include/Error.hpp
@@ -18,12 +18,16 @@ class Error
   std::string gold;
   Classifier::WeightedActions weightedActions;
   std::string type;
+  int indexOfPrediction;
+  int indexOfGold;
+  int distanceWithGold;
   
   public :
 
   Error(std::string &, std::string &, Classifier::WeightedActions &);
   bool isError() const;
   const std::string & getType() const;
+  const bool goldWasAtDistance();
 };
 
 class ErrorSequence
diff --git a/error_correction/src/Error.cpp b/error_correction/src/Error.cpp
index 05fa782..bf94540 100644
--- a/error_correction/src/Error.cpp
+++ b/error_correction/src/Error.cpp
@@ -4,6 +4,31 @@ Error::Error(std::string & prediction, std::string & gold, Classifier::WeightedA
 prediction(prediction), gold(gold), weightedActions(weightedActions)
 {
   type = prediction + "->" + gold;
+  indexOfPrediction = -1;
+  indexOfGold = -1;
+  distanceWithGold = 0;
+
+  for (unsigned int i = 0; i < weightedActions.size(); i++)
+  {
+    if (weightedActions[i].second.second == prediction)
+      indexOfPrediction = i;
+    if (weightedActions[i].second.second == gold)
+      indexOfGold = i;
+    if (weightedActions[i].first && indexOfPrediction != -1 && indexOfGold == -1)
+      distanceWithGold++;
+  }
+
+  if (indexOfPrediction == -1 || indexOfGold == -1)
+  {
+    fprintf(stderr, "ERROR (%s) : weightedActions do not contain prediction or gold. Aborting.\n", ERRINFO);
+    exit(1);
+  }
+
+  if (distanceWithGold != 0 && !isError())
+  {
+    fprintf(stderr, "ERROR (%s) : incoherent Error initialization. Aborting.\n", ERRINFO);
+    exit(1);
+  }
 }
 
 const std::string & Error::getType() const
-- 
GitLab