From 18ecfb37dac4d7203e6a39e2d154caaf131bb385 Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Fri, 28 Oct 2016 10:22:48 -0600
Subject: [PATCH] Moved loading of scores into separate function

---
 bob/measure/load.py | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/bob/measure/load.py b/bob/measure/load.py
index d599656..55d2a48 100644
--- a/bob/measure/load.py
+++ b/bob/measure/load.py
@@ -93,16 +93,8 @@ def four_column(filename):
     float: The result of the comparison of the model and the probe
 
   """
+  return _iterate_score_file(filename)
 
-  opened = open_file(filename, 'rb')
-  if sys.version_info.major > 2:
-    import io
-    opened = io.TextIOWrapper(opened, newline="")
-
-  reader = csv.reader(opened, delimiter=' ')
-  for splits in reader:
-    splits[-1] = float(splits[-1])
-    yield splits
 
 
 def split_four_column(filename):
@@ -220,15 +212,7 @@ def five_column(filename):
 
   """
 
-  opened = open_file(filename, 'rb')
-  if sys.version_info.major > 2:
-    import io
-    opened = io.TextIOWrapper(opened, newline="")
-
-  reader = csv.reader(opened, delimiter=' ')
-  for splits in reader:
-    splits[-1] = float(splits[-1])
-    yield splits
+  return _iterate_score_file(filename)
 
 
 def split_five_column(filename):
@@ -421,6 +405,22 @@ def dump_score(filename, score_lines):
   numpy.savetxt(filename, score_lines, fmt=fmt)
 
 
+def _iterate_score_file(filename):
+  """Opens the score file for reading and yields the score file line by line in a tuple/list.
+
+  The last element of the line (which is the score) will be transformed to float, the other elements will be str
+  """
+  opened = open_file(filename, 'rb')
+  if sys.version_info.major > 2:
+    import io
+    opened = io.TextIOWrapper(opened, newline="")
+
+  reader = csv.reader(opened, delimiter=' ')
+  for splits in reader:
+    splits[-1] = float(splits[-1])
+    yield splits
+
+
 def _split_scores(score_lines, real_id_index, claimed_id_index = 0, score_index = -1):
   """Take the output of :py:func:`four_column` or :py:func:`five_column` and return negatives and positives.
   """
-- 
GitLab