From a810684055082effa732e9f10841d138845556f0 Mon Sep 17 00:00:00 2001
From: Daniel Ecer <de-code@users.noreply.github.com>
Date: Tue, 1 Aug 2017 11:30:50 +0100
Subject: [PATCH] map main paragraph to section paragraph

---
 color_map.conf                        | 11 +++++++++--
 color_map_selected.conf               | 12 +++++++++---
 sciencebeam_gym/trainer/preprocess.py | 12 ++++++++----
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/color_map.conf b/color_map.conf
index 7399535..5bda62b 100644
--- a/color_map.conf
+++ b/color_map.conf
@@ -48,8 +48,15 @@
 22=(220,20,60)
 #reference_list_title - #b8860b
 23=(184,134,11)
+
 #main_paragraph - #ff1493
-24=(255,20,147)
+#moved to alias
+#24=(255,20,147)
+
+[color_alias]
+# aliases are processed within the preprocessing step
+#main_paragraph - almost same as section_paragraph
+24=(128,0,128)
 
 [color_labels]
 1=abstract
@@ -75,5 +82,5 @@
 21=acknowledgement
 22=reference
 23=reference_list_title
-24=main_paragraph
+# 24=main_paragraph
 
diff --git a/color_map_selected.conf b/color_map_selected.conf
index d90951e..ee129ae 100644
--- a/color_map_selected.conf
+++ b/color_map_selected.conf
@@ -48,8 +48,15 @@
 #22=(220,20,60)
 #reference_list_title - #b8860b
 #23=(184,134,11)
+
 #main_paragraph - #ff1493
-24=(255,20,147)
+#moved to alias
+#24=(255,20,147)
+
+[color_alias]
+# aliases are processed within the preprocessing step
+#main_paragraph - almost same as section_paragraph
+24=(128,0,128)
 
 [color_labels]
 1=abstract
@@ -75,5 +82,4 @@
 #21=acknowledgement
 #22=reference
 #23=reference_list_title
-24=main_paragraph
-
+#24=main_paragraph
diff --git a/sciencebeam_gym/trainer/preprocess.py b/sciencebeam_gym/trainer/preprocess.py
index 686e105..0a2f2d1 100644
--- a/sciencebeam_gym/trainer/preprocess.py
+++ b/sciencebeam_gym/trainer/preprocess.py
@@ -43,7 +43,9 @@ slim = tf.contrib.slim
 
 error_count = Metrics.counter('main', 'errorCount')
 
-def parse_color_map(f):
+def parse_color_map(f, section_names=None):
+  if section_names is None:
+    section_names = ['color_map']
   color_map_config = ConfigParser()
   color_map_config.readfp(f)
 
@@ -62,8 +64,10 @@ def parse_color_map(f):
     raise Exception('invalid color value: {}'.format(s))
 
   color_map = dict()
-  for k, v in color_map_config.items('color_map'):
-    color_map[parse_color(k)] = parse_color(v)
+  for section_name in section_names:
+    if color_map_config.has_section(section_name):
+      for k, v in color_map_config.items(section_name):
+        color_map[parse_color(k)] = parse_color(v)
   return color_map
 
 def map_colors(img, color_map):
@@ -198,7 +202,7 @@ def configure_pipeline(p, opt):
   color_map = None
   if opt.color_map:
     with file_io.FileIO(opt.color_map, 'r') as config_f:
-      color_map = parse_color_map(config_f)
+      color_map = parse_color_map(config_f, section_names=['color_alias', 'color_map'])
   if color_map:
     logger.info('read {} color mappings'.format(len(color_map)))
   else:
-- 
GitLab