ripple-down-rules 0.5.96__py3-none-any.whl → 0.5.97__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.5.96"
1
+ __version__ = "0.5.97"
2
2
 
3
3
  import logging
4
4
  logger = logging.Logger("rdr")
ripple_down_rules/rdr.py CHANGED
@@ -676,12 +676,12 @@ class SingleClassRDR(RDRWithCodeWriter):
676
676
  :param case_query: The case query containing the case and the target category to compare the case with.
677
677
  """
678
678
  pred = self.evaluate(case)
679
- conclusion = pred.conclusion(case) if pred is not None else None
679
+ conclusion = pred.conclusion(case) if pred is not None else self.default_conclusion
680
680
  if pred is not None and pred.fired and case_query is not None:
681
681
  if pred.corner_case_metadata is None and conclusion is not None \
682
682
  and type(conclusion) in case_query.core_attribute_type:
683
683
  pred.corner_case_metadata = CaseFactoryMetaData.from_case_query(case_query)
684
- return conclusion if pred is not None and pred.fired else self.default_conclusion
684
+ return conclusion
685
685
 
686
686
  def evaluate(self, case: Case) -> SingleClassRule:
687
687
  """
@@ -31,7 +31,8 @@ class RDRDecorator:
31
31
  expert: Optional[Expert] = None,
32
32
  update_existing_rules: bool = True,
33
33
  viewer: Optional[RDRCaseViewer] = None,
34
- package_name: Optional[str] = None):
34
+ package_name: Optional[str] = None,
35
+ use_generated_classifier: bool = False):
35
36
  """
36
37
  :param models_dir: The directory to save/load the RDR models.
37
38
  :param output_type: The type of the output. This is used to create the RDR model.
@@ -47,6 +48,7 @@ class RDRDecorator:
47
48
  even if they gave an output.
48
49
  :param viewer: The viewer to use for the RDR model. If None, no viewer will be used.
49
50
  :param package_name: The package name to use for relative imports in the RDR model.
51
+ :param use_generated_classifier: If True, the function will use the generated classifier instead of the RDR model.
50
52
  :return: A decorator to use a GeneralRDR as a classifier that monitors and modifies the function's output.
51
53
  """
52
54
  self.rdr_models_dir = models_dir
@@ -60,6 +62,8 @@ class RDRDecorator:
60
62
  self.update_existing_rules = update_existing_rules
61
63
  self.viewer = viewer
62
64
  self.package_name = package_name
65
+ self.use_generated_classifier = use_generated_classifier
66
+ self.generated_classifier: Optional[Callable] = None
63
67
  self.load()
64
68
 
65
69
  def decorator(self, func: Callable) -> Callable:
@@ -67,17 +71,17 @@ class RDRDecorator:
67
71
  @wraps(func)
68
72
  def wrapper(*args, **kwargs) -> Optional[Any]:
69
73
 
70
- if len(self.parsed_output_type) == 0:
71
- self.parsed_output_type = self.parse_output_type(func, self.output_type, *args)
72
74
  if self.model_name is None:
73
75
  self.initialize_rdr_model_name_and_load(func)
74
- if self.expert is None:
75
- self.expert = Human(viewer=self.viewer,
76
- answers_save_path=self.rdr_models_dir + f'/{self.model_name}/expert_answers')
77
76
 
78
77
  func_output = {self.output_name: func(*args, **kwargs)}
79
78
 
80
79
  if self.fit:
80
+ if len(self.parsed_output_type) == 0:
81
+ self.parsed_output_type = self.parse_output_type(func, self.output_type, *args)
82
+ if self.expert is None:
83
+ self.expert = Human(viewer=self.viewer,
84
+ answers_save_path=self.rdr_models_dir + f'/{self.model_name}/expert_answers')
81
85
  case_query = self.create_case_query_from_method(func, func_output,
82
86
  self.parsed_output_type,
83
87
  self.mutual_exclusive,
@@ -87,7 +91,13 @@ class RDRDecorator:
87
91
  viewer=self.viewer)
88
92
  else:
89
93
  case, case_dict = self.create_case_from_method(func, func_output, *args, **kwargs)
90
- output = self.rdr.classify(case)
94
+ if self.use_generated_classifier:
95
+ if self.generated_classifier is None:
96
+ model_path = os.path.join(self.rdr_models_dir, self.model_name)
97
+ self.generated_classifier = self.rdr.get_rdr_classifier_from_python_file(model_path)
98
+ output = self.generated_classifier(case)
99
+ else:
100
+ output = self.rdr.classify(case)
91
101
 
92
102
  if self.output_name in output:
93
103
  return output[self.output_name]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.5.96
3
+ Version: 0.5.97
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,8 +1,8 @@
1
- ripple_down_rules/__init__.py,sha256=Vzq2IW363zvjMh2-NN_nmo2dJIZaUhzlFSMP3GpB8i0,100
1
+ ripple_down_rules/__init__.py,sha256=S8_aIL6wZaWbPQRl_qf9q65NR3nW8mnLIrjc-Tqvvaw,100
2
2
  ripple_down_rules/experts.py,sha256=4-dMIVeMzFXCLYl_XBG_P7_Xs4sZih9-vZxCIPri6dA,12958
3
3
  ripple_down_rules/helpers.py,sha256=sY8nFbYdLOO6EG5UQugCCxjSjcCQsDUCPgawfQA4Ui8,4495
4
- ripple_down_rules/rdr.py,sha256=JqNPCUHDJ9xBg8pReYAMas9hlC_BBRZdqtl1cO2NMmU,56177
5
- ripple_down_rules/rdr_decorators.py,sha256=riAFmL8jc1rw9dFkNbT023CfB5FbmOWHNiVKO2bAXsE,9195
4
+ ripple_down_rules/rdr.py,sha256=CPSjSmdzUN5meBakr9T6B-ZT1KmLjRAJ6JIL3UIRzyI,56132
5
+ ripple_down_rules/rdr_decorators.py,sha256=JWJn2MAKJG1YbLLWUZMzYfS3t1mEOAi21S8NUY7hy0Q,9913
6
6
  ripple_down_rules/rules.py,sha256=Dk4yGCy5oV10mOv5rRLcmtIu9J60WBPol9b7ELFn6fY,21522
7
7
  ripple_down_rules/start-code-server.sh,sha256=otClk7VmDgBOX2TS_cjws6K0UwvgAUJhoA0ugkPCLqQ,949
8
8
  ripple_down_rules/utils.py,sha256=vFoz5HcRgkf7_s-zdWSg54xI9PCMcdDzcdFGdas7KBA,62350
@@ -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.5.96.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
- ripple_down_rules-0.5.96.dist-info/METADATA,sha256=k8TDjtJGrXRcD7pOO6fxVD2kqEJf4Em7_ro1h55jjZ0,48214
22
- ripple_down_rules-0.5.96.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- ripple_down_rules-0.5.96.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
- ripple_down_rules-0.5.96.dist-info/RECORD,,
20
+ ripple_down_rules-0.5.97.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
+ ripple_down_rules-0.5.97.dist-info/METADATA,sha256=ATXJ3z-nJQQ3aB9aFaEnEfXLJ7njVA1Kh1s40tJPBV0,48214
22
+ ripple_down_rules-0.5.97.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ ripple_down_rules-0.5.97.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
+ ripple_down_rules-0.5.97.dist-info/RECORD,,