ripple-down-rules 0.4.85__py3-none-any.whl → 0.4.88__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 +1,5 @@
1
- __version__ = "0.4.85"
1
+ __version__ = "0.4.88"
2
+
3
+ import logging
4
+ logger = logging.Logger("rdr")
5
+ logger.setLevel(logging.INFO)
@@ -354,11 +354,13 @@ def show_current_and_corner_cases(case: Any, targets: Optional[Dict[str, Any]] =
354
354
  if last_evaluated_rule and last_evaluated_rule.fired:
355
355
  corner_row_dict = copy_case(corner_case)
356
356
 
357
+ case_dict.update(targets)
358
+ case_dict.update(current_conclusions)
359
+ all_table_rows = [case_dict]
357
360
  if corner_row_dict:
358
361
  corner_conclusion = last_evaluated_rule.conclusion(case)
359
362
  corner_row_dict.update({corner_conclusion.__class__.__name__: corner_conclusion})
360
- print(table_rows_as_str(corner_row_dict))
361
- print("=" * 50)
362
- case_dict.update(targets)
363
- case_dict.update(current_conclusions)
364
- print(table_rows_as_str(case_dict))
363
+ all_table_rows.append(corner_row_dict)
364
+ # print(table_rows_as_str(corner_row_dict))
365
+ print("\n" + "=" * 50)
366
+ print(table_rows_as_str(all_table_rows))
ripple_down_rules/rdr.py CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import copyreg
4
4
  import importlib
5
- import logging
5
+ from . import logger
6
6
  import sys
7
7
  from abc import ABC, abstractmethod
8
8
  from copy import copy
@@ -13,7 +13,7 @@ try:
13
13
  from matplotlib import pyplot as plt
14
14
  Figure = plt.Figure
15
15
  except ImportError as e:
16
- logging.debug(f"{e}: matplotlib is not installed")
16
+ logger.debug(f"{e}: matplotlib is not installed")
17
17
  matplotlib = None
18
18
  Figure = None
19
19
  plt = None
@@ -122,13 +122,13 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
122
122
  all_predictions = [1 if is_matching(self.classify, case_query) else 0 for case_query in case_queries
123
123
  if case_query.target is not None]
124
124
  all_pred = sum(all_predictions)
125
- print(f"Accuracy: {all_pred}/{len(targets)}")
125
+ logger.info(f"Accuracy: {all_pred}/{len(targets)}")
126
126
  all_predicted = targets and all_pred == len(targets)
127
127
  num_iter_reached = n_iter and i >= n_iter
128
128
  stop_iterating = all_predicted or num_iter_reached
129
129
  if stop_iterating:
130
130
  break
131
- print(f"Finished training in {i} iterations")
131
+ logger.info(f"Finished training in {i} iterations")
132
132
  if animate_tree:
133
133
  plt.ioff()
134
134
  plt.show()
@@ -360,15 +360,13 @@ class RDRWithCodeWriter(RippleDownRules, ABC):
360
360
  return importlib.import_module(name).classify
361
361
 
362
362
  @property
363
- def _default_generated_python_file_name(self) -> str:
363
+ def _default_generated_python_file_name(self) -> Optional[str]:
364
364
  """
365
365
  :return: The default generated python file name.
366
366
  """
367
- if isinstance(self.start_rule.corner_case, Case):
368
- name = self.start_rule.corner_case._name
369
- else:
370
- name = self.start_rule.corner_case.__class__.__name__
371
- return f"{name.lower()}_{self.attribute_name}_{self.acronym.lower()}"
367
+ if self.start_rule is None or self.start_rule.conclusion is None:
368
+ return None
369
+ return f"{self.case_type.__name__.lower()}_{self.attribute_name}_{self.acronym.lower()}"
372
370
 
373
371
  @property
374
372
  def generated_python_defs_file_name(self) -> str:
@@ -958,11 +956,7 @@ class GeneralRDR(RippleDownRules):
958
956
  """
959
957
  if self.start_rule is None or self.start_rule.conclusion is None:
960
958
  return None
961
- if isinstance(self.start_rule.corner_case, Case):
962
- name = self.start_rule.corner_case._name
963
- else:
964
- name = self.start_rule.corner_case.__class__.__name__
965
- return f"{name}_rdr".lower()
959
+ return f"{self.case_type.__name__.lower()}_rdr".lower()
966
960
 
967
961
  @property
968
962
  def conclusion_type_hint(self) -> str:
@@ -1098,24 +1098,29 @@ def get_origin_and_args_from_type_hint(type_hint: Type) -> Tuple[Optional[Type],
1098
1098
  return origin, args
1099
1099
 
1100
1100
 
1101
- def table_rows_as_str(row_dict: Dict[str, Any], columns_per_row: int = 9):
1101
+ def table_rows_as_str(row_dicts: List[Dict[str, Any]], columns_per_row: int = 20):
1102
1102
  """
1103
1103
  Print a table row.
1104
1104
 
1105
- :param row_dict: The row to print.
1105
+ :param row_dicts: The rows to print.
1106
1106
  :param columns_per_row: The maximum number of columns per row.
1107
1107
  """
1108
- all_items = list(row_dict.items())
1108
+ all_row_dicts_items = [list(row_dict.items()) for row_dict in row_dicts]
1109
1109
  # make items a list of n rows such that each row has a max size of 4
1110
- all_items = [all_items[i:i + columns_per_row] for i in range(0, len(all_items), columns_per_row)]
1110
+ all_items = [all_items[i:i + columns_per_row] for all_items in all_row_dicts_items
1111
+ for i in range(0, len(all_items), columns_per_row)]
1111
1112
  keys = [list(map(lambda i: i[0], row)) for row in all_items]
1112
1113
  values = [list(map(lambda i: i[1], row)) for row in all_items]
1114
+ zipped_keys = list(zip(*keys))
1115
+ zipped_values = list(zip(*values))
1116
+ keys_values = [list(zip(zipped_keys[i], zipped_values[i])) for i in range(len(zipped_keys))]
1117
+ keys_values = [list(r[0]) + list(r[1]) if len(r) > 1 else r[0] for r in keys_values]
1113
1118
  all_table_rows = []
1114
- for row_keys, row_values in zip(keys, values):
1115
- row_values = [str(v) if v is not None else "" for v in row_values]
1116
- row_values = [v.lower() if v in ["True", "False"] else v for v in row_values]
1117
- table = tabulate([row_values], headers=row_keys, tablefmt='plain', maxcolwidths=[20] * len(row_keys))
1118
- all_table_rows.append(table)
1119
+ row_values = [list(map(lambda v: str(v) if v is not None else "", row)) for row in keys_values]
1120
+ row_values = [list(map(lambda v: v[:150] + '...' if len(v) > 150 else v, row)) for row in row_values]
1121
+ row_values = [list(map(lambda v: v.lower() if v in ["True", "False"] else v, row)) for row in row_values]
1122
+ table = tabulate(row_values, tablefmt='simple_grid', maxcolwidths=[150] * 2)
1123
+ all_table_rows.append(table)
1119
1124
  return "\n".join(all_table_rows)
1120
1125
 
1121
1126
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.4.85
3
+ Version: 0.4.88
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
@@ -693,20 +693,12 @@ Requires-Dist: colorama
693
693
  Requires-Dist: pygments
694
694
  Requires-Dist: sqlalchemy
695
695
  Requires-Dist: pandas
696
+ Provides-Extra: viz
697
+ Requires-Dist: networkx>=3.1; extra == "viz"
698
+ Requires-Dist: matplotlib>=3.7.5; extra == "viz"
696
699
  Provides-Extra: gui
697
700
  Requires-Dist: pyqt6; extra == "gui"
698
701
  Requires-Dist: qtconsole; extra == "gui"
699
- Provides-Extra: viz
700
- Requires-Dist: matplotlib; extra == "viz"
701
- Requires-Dist: networkx; extra == "viz"
702
- Provides-Extra: dev
703
- Requires-Dist: pyqt6; extra == "dev"
704
- Requires-Dist: qtconsole; extra == "dev"
705
- Requires-Dist: matplotlib; extra == "dev"
706
- Requires-Dist: networkx; extra == "dev"
707
- Requires-Dist: pytest; extra == "dev"
708
- Requires-Dist: ucimlrepo>=0.0.7; extra == "dev"
709
- Requires-Dist: pdbpp; extra == "dev"
710
702
  Dynamic: license-file
711
703
 
712
704
  # Ripple Down Rules (RDR)
@@ -1,16 +1,16 @@
1
- ripple_down_rules/__init__.py,sha256=BOEwGNbbzGrJYVxU-YvP8hmmJwQ3P8zGs6QDgP4yccA,22
1
+ ripple_down_rules/__init__.py,sha256=gvXUS_xmUCsWcUwVy5Sd8tyjdLhlPGbjfDrfDImrt7o,100
2
2
  ripple_down_rules/datasets.py,sha256=fJbZ7V-UUYTu5XVVpFinTbuzN3YePCnUB01L3AyZVM8,6837
3
3
  ripple_down_rules/experts.py,sha256=RWDR-xxbeFIrUQiMYLEDr_PLQFdpPZ-hOXo4dpeiUpI,6630
4
4
  ripple_down_rules/failures.py,sha256=E6ajDUsw3Blom8eVLbA7d_Qnov2conhtZ0UmpQ9ZtSE,302
5
5
  ripple_down_rules/helpers.py,sha256=TvTJU0BA3dPcAyzvZFvAu7jZqsp8Lu0HAAwvuizlGjg,2018
6
- ripple_down_rules/rdr.py,sha256=qELIEEokGTWj-VBZZeEM_TiHxaWrlvaKRt2qShuxfvo,45739
6
+ ripple_down_rules/rdr.py,sha256=a7sSxvJewzG5FZvbUW_Ss7VVYQtBnH-H--hni8-pWC4,45528
7
7
  ripple_down_rules/rdr_decorators.py,sha256=VdmE0JrE8j89b6Af1R1tLZiKfy3h1VCvhAUefN_FLLQ,6753
8
8
  ripple_down_rules/rules.py,sha256=7NB8qWW7XEB45tmJRYsKJqBG8DN3v02fzAFYmOkX8ow,17458
9
9
  ripple_down_rules/start-code-server.sh,sha256=otClk7VmDgBOX2TS_cjws6K0UwvgAUJhoA0ugkPCLqQ,949
10
- ripple_down_rules/utils.py,sha256=iM2bYRYanuWTnq7dflRar8tMwRxL88B__hWkayGLVz4,50675
10
+ ripple_down_rules/utils.py,sha256=t_yutgZvrOOGb6Wa-uAuoTafLicwovSFRiUa746ALOw,51108
11
11
  ripple_down_rules/datastructures/__init__.py,sha256=V2aNgf5C96Y5-IGghra3n9uiefpoIm_QdT7cc_C8cxQ,111
12
12
  ripple_down_rules/datastructures/callable_expression.py,sha256=jA7424_mWPbOoPICW3eLMX0-ypxnsW6gOqxrJ7JpDbE,11610
13
- ripple_down_rules/datastructures/case.py,sha256=3nGeTv9JYpnRSmsHCt61qo1QT4d9Dfkl9KrZ7I6E2kk,15164
13
+ ripple_down_rules/datastructures/case.py,sha256=r8kjL9xP_wk84ThXusspgPMrAoed2bGQmKi54fzhmH8,15258
14
14
  ripple_down_rules/datastructures/dataclasses.py,sha256=GWnUF4h4zfNHSsyBIz3L9y8sLkrXRv0FK_OxzzLc8L8,8183
15
15
  ripple_down_rules/datastructures/enums.py,sha256=ce7tqS0otfSTNAOwsnXlhsvIn4iW_Y_N3TNebF3YoZs,5700
16
16
  ripple_down_rules/user_interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -19,8 +19,8 @@ ripple_down_rules/user_interface/ipython_custom_shell.py,sha256=24MIFwqnAhC6ofOb
19
19
  ripple_down_rules/user_interface/object_diagram.py,sha256=tsB6iuLNEbHxp5lR2WjyejjWbnAX_nHF9xS8jNPOQVk,4548
20
20
  ripple_down_rules/user_interface/prompt.py,sha256=AkkltdDIaioN43lkRKDPKSjJcmdSSGZDMYz7AL7X9lE,8082
21
21
  ripple_down_rules/user_interface/template_file_creator.py,sha256=J_bBOJltc1fsrIYeHdrSUA_jep2DhDbTK5NYRbL6QyY,13831
22
- ripple_down_rules-0.4.85.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
23
- ripple_down_rules-0.4.85.dist-info/METADATA,sha256=aNYxUv8mZ4KV4guZL6pJ2WiNXHi6Vfh4T_YRWbmMU_A,43598
24
- ripple_down_rules-0.4.85.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
25
- ripple_down_rules-0.4.85.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
26
- ripple_down_rules-0.4.85.dist-info/RECORD,,
22
+ ripple_down_rules-0.4.88.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
23
+ ripple_down_rules-0.4.88.dist-info/METADATA,sha256=ytWRoIfcAHeBfJMqT1KtQJPsAEGDqXZZegjDaq6YcuM,43307
24
+ ripple_down_rules-0.4.88.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
25
+ ripple_down_rules-0.4.88.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
26
+ ripple_down_rules-0.4.88.dist-info/RECORD,,