ripple-down-rules 0.6.20__py3-none-any.whl → 0.6.21__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- __version__ = "0.6.20"
1
+ __version__ = "0.6.21"
2
2
 
3
3
  import logging
4
4
  logger = logging.Logger("rdr")
ripple_down_rules/rdr.py CHANGED
@@ -110,7 +110,7 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
110
110
 
111
111
  def render_evaluated_rule_tree(self, filename: str) -> None:
112
112
  evaluated_rules = self.get_evaluated_rule_tree()
113
- if len(evaluated_rules) > 0:
113
+ if evaluated_rules is not None and len(evaluated_rules) > 0:
114
114
  render_tree(evaluated_rules[0], use_dot_exporter=True, filename=filename,
115
115
  only_nodes=evaluated_rules)
116
116
 
@@ -121,7 +121,8 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
121
121
  :return: The evaluated rule tree.
122
122
  """
123
123
  if self.start_rule is None:
124
- raise ValueError("The start rule is not set. Please set the start rule before getting the evaluated rule tree.")
124
+ return
125
+ # raise ValueError("The start rule is not set. Please set the start rule before getting the evaluated rule tree.")
125
126
  evaluated_rule_tree = [r for r in [self.start_rule] + list(self.start_rule.descendants) if r.evaluated]
126
127
  return evaluated_rule_tree
127
128
 
@@ -75,6 +75,7 @@ class RDRDecorator:
75
75
  self.fitting_decorator = fitting_decorator if fitting_decorator is not None else \
76
76
  lambda f: f # Default to no fitting decorator
77
77
  self.generate_dot_file = generate_dot_file
78
+ self.not_none_output_found: bool = False
78
79
  self.load()
79
80
 
80
81
  def decorator(self, func: Callable) -> Callable:
@@ -117,7 +118,11 @@ class RDRDecorator:
117
118
  else:
118
119
  output = self.rdr.classify(case)
119
120
  if self.generate_dot_file:
120
- self.rdr.render_evaluated_rule_tree(self.rdr_models_dir + f'/{self.model_name}')
121
+ eval_rule_tree = self.rdr.get_evaluated_rule_tree()
122
+ if not self.not_none_output_found or (eval_rule_tree and len(eval_rule_tree) > 1):
123
+ self.rdr.render_evaluated_rule_tree(self.rdr_models_dir + f'/{self.model_name}')
124
+ if eval_rule_tree and len(eval_rule_tree) > 1:
125
+ self.not_none_output_found = True
121
126
 
122
127
  if self.output_name in output:
123
128
  return output[self.output_name]
@@ -1839,7 +1839,7 @@ class FilteredDotExporter(object):
1839
1839
  continue
1840
1840
  nodeattr = nodeattrfunc(node)
1841
1841
  nodeattr = " [%s]" % nodeattr if nodeattr is not None else ""
1842
- yield '%s"%s"%s;' % (indent, DotExporter.esc(nodename), nodeattr)
1842
+ yield '%s"%s"%s;' % (indent, FilteredDotExporter.esc(nodename), nodeattr)
1843
1843
 
1844
1844
  def __iter_edges(self, indent, nodenamefunc, edgeattrfunc, edgetypefunc):
1845
1845
  maxlevel = self.maxlevel - 1 if self.maxlevel else None
@@ -1854,8 +1854,8 @@ class FilteredDotExporter(object):
1854
1854
  edgeattr = edgeattrfunc(node, child)
1855
1855
  edgetype = edgetypefunc(node, child)
1856
1856
  edgeattr = " [%s]" % edgeattr if edgeattr is not None else ""
1857
- yield '%s"%s" %s "%s"%s;' % (indent, DotExporter.esc(nodename), edgetype,
1858
- DotExporter.esc(childname), edgeattr)
1857
+ yield '%s"%s" %s "%s"%s;' % (indent, FilteredDotExporter.esc(nodename), edgetype,
1858
+ FilteredDotExporter.esc(childname), edgeattr)
1859
1859
 
1860
1860
  def to_dotfile(self, filename):
1861
1861
  """
@@ -1925,18 +1925,19 @@ def render_tree(root: Node, use_dot_exporter: bool = False,
1925
1925
  if not root:
1926
1926
  logging.warning("No rules to render")
1927
1927
  return
1928
- for pre, _, node in RenderTree(root):
1929
- print(f"{pre}{node.weight if hasattr(node, 'weight') and node.weight else ''} {node.__str__()}")
1928
+ # for pre, _, node in RenderTree(root):
1929
+ # print(f"{pre}{node.weight if hasattr(node, 'weight') and node.weight else ''} {node.__str__()}")
1930
1930
  if use_dot_exporter:
1931
1931
  unique_node_names = get_unique_node_names_func(root)
1932
1932
 
1933
1933
  de = FilteredDotExporter(root,
1934
1934
  include_nodes=only_nodes,
1935
1935
  nodenamefunc=unique_node_names,
1936
- edgeattrfunc=edge_attr_setter
1936
+ edgeattrfunc=edge_attr_setter,
1937
+ nodeattrfunc=lambda node: f'style=filled, fillcolor={"green" if node.fired else "red"}'
1937
1938
  )
1938
1939
  de.to_dotfile(f"{filename}{'.dot'}")
1939
- de.to_picture(f"{filename}{'.png'}")
1940
+ # de.to_picture(f"{filename}{'.png'}")
1940
1941
 
1941
1942
 
1942
1943
  def draw_tree(root: Node, fig: Figure):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.6.20
3
+ Version: 0.6.21
4
4
  Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
5
5
  Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,11 +1,11 @@
1
- ripple_down_rules/__init__.py,sha256=xpB0ANrfA5A060d9mDqT8Wy9YWsSGJIlfSH6X5JBu4E,100
1
+ ripple_down_rules/__init__.py,sha256=FE7egOk8_N_vJLm9yZ7ZIh8wz0opNbBXT1V2le4qaog,100
2
2
  ripple_down_rules/experts.py,sha256=4-dMIVeMzFXCLYl_XBG_P7_Xs4sZih9-vZxCIPri6dA,12958
3
3
  ripple_down_rules/helpers.py,sha256=RUdfiSWMZjGwCxuCy44TcEJf2UNAFlPJusgHzuAs6qI,4583
4
- ripple_down_rules/rdr.py,sha256=mtY_kBOjUXRZYz4QFaKN6C2O7liFpbMdnjUnFFnXbdU,57550
5
- ripple_down_rules/rdr_decorators.py,sha256=fxoMMAZB1HTfEsuzfIdo3b7PiPB_-AAjD8hy4L0sawQ,11389
4
+ ripple_down_rules/rdr.py,sha256=nUPapnkz9cESaeDDZ8iYdrzmED59nIbZWB19a-lYYr4,57603
5
+ ripple_down_rules/rdr_decorators.py,sha256=QafdWzfbjE-xYe2SyIDr7oRqq32WjKYBC2LrG2I3iy0,11758
6
6
  ripple_down_rules/rules.py,sha256=ULIHRbVfKd2L3zzPnssmaeqInWHifPvwwa16MyzakPc,23548
7
7
  ripple_down_rules/start-code-server.sh,sha256=otClk7VmDgBOX2TS_cjws6K0UwvgAUJhoA0ugkPCLqQ,949
8
- ripple_down_rules/utils.py,sha256=mhvwBEyGhwAYocBYjAlmFh192pEvYrx-KObnMa1aSnk,73189
8
+ ripple_down_rules/utils.py,sha256=Pwvi51zXE2zZN1RYmsX4xUxPMHs3lXIYirPrUyOiwpk,73341
9
9
  ripple_down_rules/datastructures/__init__.py,sha256=V2aNgf5C96Y5-IGghra3n9uiefpoIm_QdT7cc_C8cxQ,111
10
10
  ripple_down_rules/datastructures/callable_expression.py,sha256=ysK-4JmZ4oSUTJC7zpo_o77g4ONxPDEcIpSWggsnx3c,13320
11
11
  ripple_down_rules/datastructures/case.py,sha256=PJ7_-AdxYic6BO5z816piFODj6nU5J6Jt1YzTFH-dds,15510
@@ -17,8 +17,8 @@ ripple_down_rules/user_interface/ipython_custom_shell.py,sha256=yp-F8YRWGhj1PLB3
17
17
  ripple_down_rules/user_interface/object_diagram.py,sha256=FEa2HaYR9QmTE6NsOwBvZ0jqmu3DKyg6mig2VE5ZP4Y,4956
18
18
  ripple_down_rules/user_interface/prompt.py,sha256=JceEUGYsd0lIvd-v2y3D3swoo96_C0lxfp3CxM7Vfts,8900
19
19
  ripple_down_rules/user_interface/template_file_creator.py,sha256=kwBbFLyN6Yx2NTIHPSwOoytWgbJDYhgrUOVFw_jkDQ4,13522
20
- ripple_down_rules-0.6.20.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
- ripple_down_rules-0.6.20.dist-info/METADATA,sha256=XE3l7CrRsjXZLfW5LpHoYTJbIVT9rOHKr9S3qWVqGyA,48294
22
- ripple_down_rules-0.6.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- ripple_down_rules-0.6.20.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
- ripple_down_rules-0.6.20.dist-info/RECORD,,
20
+ ripple_down_rules-0.6.21.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
+ ripple_down_rules-0.6.21.dist-info/METADATA,sha256=Ir6V_9HK_ELD1EdVwrzu7noYUDY21VwIMC1SP0708UA,48294
22
+ ripple_down_rules-0.6.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ ripple_down_rules-0.6.21.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
+ ripple_down_rules-0.6.21.dist-info/RECORD,,