From 53705fcad21cbfd59511627a0ba342d055a5c6e2 Mon Sep 17 00:00:00 2001
From: Anne-Liza <a.m.r.m.bruggeman@student.tudelft.nl>
Date: Thu, 5 Oct 2017 13:07:44 +0200
Subject: [PATCH] Added option to choose labeling method for equation labels

Former-commit-id: 6a3dc36c845b6a0c7801959f87c053368305872d
---
 kadmos/graph/mixin_equation.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/kadmos/graph/mixin_equation.py b/kadmos/graph/mixin_equation.py
index 2f8d94669..c9c2895d1 100644
--- a/kadmos/graph/mixin_equation.py
+++ b/kadmos/graph/mixin_equation.py
@@ -75,14 +75,14 @@ class EquationMixin(object):
 
         return chars
 
-    def add_equation_label(self, edge, label=None, language='Python'):
+    def add_equation_label(self, edge, labeling_method='node_label', language='Python'):
         """Method to add an equation label to a edge that can (safely) be used as reference in an equation.
 
         :type self: KadmosGraph
         :param edge: graph edge under consideration
         :type edge: str
-        :param label: label to be added (if not given it will be determined based on the node label or key)
-        :type label: str
+        :param labeling_method: select method for automatic label string determination (node_id or node_label)
+        :type labeling_method: str
         :param language: equation language used for the equation label
         :type language: str
 
@@ -94,9 +94,16 @@ class EquationMixin(object):
         assert self.has_edge(edge[0], edge[1]), 'Edge %s does not exist.' % edge
 
         # If the label is not provided retrieve it automatically from the variable node
-        if label is None:
-            variable = edge[0] if self.node[edge[0]].get('category') == 'variable' else edge[1]
-            label = self.node[variable].get('label', variable)
+        node_id = edge[0] if self.node[edge[0]].get('category') == 'variable' else edge[1]
+        if labeling_method == 'node_label':
+            label = self.node[node_id].get('label', node_id)
+        elif labeling_method == 'node_id':
+            label = node_id.split('/')[-1]
+        else:
+            raise IOError('Invalid setting label_method.')
+
+
+
 
         # Make the label valid
         for char in self._get_equation_chars(language=language):
@@ -112,7 +119,7 @@ class EquationMixin(object):
 
         return label
 
-    def add_equation_labels(self, nodes, language='Python'):
+    def add_equation_labels(self, nodes, language='Python', labeling_method='node_id'):
         """Method to add equation labels automatically to all input edges connected to the specified list of nodes
 
         :type self: KadmosGraph
@@ -120,6 +127,8 @@ class EquationMixin(object):
         :type nodes: list
         :param language: equation language used for the equation label
         :type language: str
+        :param labeling_method: select method for automatic label string determination (node_id or node_label)
+        :type labeling_method: str
         """
 
         # Find all input edges
@@ -127,7 +136,7 @@ class EquationMixin(object):
 
         # Loop
         for edge in in_edges:
-            self.add_equation_label(edge, language=language)
+            self.add_equation_label(edge, labeling_method=labeling_method, language=language)
 
         return
 
@@ -181,7 +190,6 @@ class EquationMixin(object):
         cmdows_added_equations = dict()
 
         for graph_math_func in graph_math_funcs:
-
             # Create mathematicalFunctions/mathematicalFunction
             cmdows_math_func = cmdows_math_funcs.add('mathematicalFunction', uID=graph_math_func)
             cmdows_math_func.add('label', self.node[graph_math_func].get('label', graph_math_func))
-- 
GitLab