Skip to content
Snippets Groups Projects
Commit 53705fca authored by Anne-Liza's avatar Anne-Liza
Browse files

Added option to choose labeling method for equation labels

Former-commit-id: 6a3dc36c845b6a0c7801959f87c053368305872d
parent 99da533c
No related branches found
Tags v0.7.3
No related merge requests found
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment