ripple-down-rules 0.4.81__py3-none-any.whl → 0.4.83__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.
ripple_down_rules/rdr.py CHANGED
@@ -22,7 +22,7 @@ from .rules import Rule, SingleClassRule, MultiClassTopRule, MultiClassStopRule
22
22
  from .user_interface.gui import RDRCaseViewer
23
23
  from .utils import draw_tree, make_set, copy_case, \
24
24
  SubclassJSONSerializer, make_list, get_type_from_string, \
25
- is_conflicting, update_case, get_imports_from_scope, extract_function_source, extract_imports
25
+ is_conflicting, update_case, get_imports_from_scope, extract_function_source, extract_imports, get_full_class_name
26
26
 
27
27
 
28
28
  class RippleDownRules(SubclassJSONSerializer, ABC):
@@ -45,6 +45,10 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
45
45
  """
46
46
  The name of the classifier.
47
47
  """
48
+ case_type: Optional[Type] = None
49
+ """
50
+ The type of the case (input) to the RDR classifier.
51
+ """
48
52
 
49
53
  def __init__(self, start_rule: Optional[Rule] = None, viewer: Optional[RDRCaseViewer] = None):
50
54
  """
@@ -143,6 +147,7 @@ class RippleDownRules(SubclassJSONSerializer, ABC):
143
147
  if case_query is None:
144
148
  raise ValueError("The case query cannot be None.")
145
149
  self.name = case_query.attribute_name if self.name is None else self.name
150
+ self.case_type = case_query.case_type if self.case_type is None else self.case_type
146
151
  if case_query.target is None:
147
152
  case_query_cp = copy(case_query)
148
153
  self.classify(case_query_cp.case, modify_case=True)
@@ -367,16 +372,6 @@ class RDRWithCodeWriter(RippleDownRules, ABC):
367
372
  else:
368
373
  return "SCRDR"
369
374
 
370
- @property
371
- def case_type(self) -> Type:
372
- """
373
- :return: The type of the case (input) to the RDR classifier.
374
- """
375
- if isinstance(self.start_rule.corner_case, Case):
376
- return self.start_rule.corner_case._obj_type
377
- else:
378
- return type(self.start_rule.corner_case)
379
-
380
375
  @property
381
376
  def conclusion_type(self) -> Tuple[Type]:
382
377
  """
@@ -396,7 +391,7 @@ class RDRWithCodeWriter(RippleDownRules, ABC):
396
391
 
397
392
  def _to_json(self) -> Dict[str, Any]:
398
393
  return {"start_rule": self.start_rule.to_json(), "generated_python_file_name": self.generated_python_file_name,
399
- "name": self.name}
394
+ "name": self.name, "case_type": get_full_class_name(self.case_type) if self.case_type is not None else None}
400
395
 
401
396
  @classmethod
402
397
  def _from_json(cls, data: Dict[str, Any]) -> Self:
@@ -409,6 +404,8 @@ class RDRWithCodeWriter(RippleDownRules, ABC):
409
404
  new_rdr.generated_python_file_name = data["generated_python_file_name"]
410
405
  if "name" in data:
411
406
  new_rdr.name = data["name"]
407
+ if "case_type" in data:
408
+ new_rdr.case_type = get_type_from_string(data["case_type"])
412
409
  return new_rdr
413
410
 
414
411
  @staticmethod
@@ -882,7 +879,8 @@ class GeneralRDR(RippleDownRules):
882
879
  def _to_json(self) -> Dict[str, Any]:
883
880
  return {"start_rules": {name: rdr.to_json() for name, rdr in self.start_rules_dict.items()}
884
881
  , "generated_python_file_name": self.generated_python_file_name,
885
- "name": self.name}
882
+ "name": self.name,
883
+ "case_type": get_full_class_name(self.case_type) if self.case_type is not None else None}
886
884
 
887
885
  @classmethod
888
886
  def _from_json(cls, data: Dict[str, Any]) -> GeneralRDR:
@@ -897,6 +895,8 @@ class GeneralRDR(RippleDownRules):
897
895
  new_rdr.generated_python_file_name = data["generated_python_file_name"]
898
896
  if "name" in data:
899
897
  new_rdr.name = data["name"]
898
+ if "case_type" in data:
899
+ new_rdr.case_type = get_type_from_string(data["case_type"])
900
900
  return new_rdr
901
901
 
902
902
  def update_from_python_file(self, package_dir: str) -> None:
@@ -930,18 +930,6 @@ class GeneralRDR(RippleDownRules):
930
930
  f"{' ' * 4} case = create_case(case, max_recursion_idx=3)\n""")
931
931
  f.write(f"{' ' * 4}return GeneralRDR._classify(classifiers_dict, case)\n")
932
932
 
933
- @property
934
- def case_type(self) -> Optional[Type]:
935
- """
936
- :return: The type of the case (input) to the RDR classifier.
937
- """
938
- if self.start_rule is None or self.start_rule.corner_case is None:
939
- return None
940
- if isinstance(self.start_rule.corner_case, Case):
941
- return self.start_rule.corner_case._obj_type
942
- else:
943
- return type(self.start_rule.corner_case)
944
-
945
933
  def get_rdr_classifier_from_python_file(self, file_path: str) -> Callable[[Any], Any]:
946
934
  """
947
935
  :param file_path: The path to the file that contains the RDR classifier function.
@@ -2,7 +2,11 @@ import ast
2
2
  import logging
3
3
  from _ast import AST
4
4
 
5
- from PyQt6.QtWidgets import QApplication
5
+ try:
6
+ from PyQt6.QtWidgets import QApplication
7
+ except ImportError:
8
+ QApplication = None
9
+
6
10
  from colorama import Fore, Style
7
11
  from pygments import highlight
8
12
  from pygments.formatters.terminal import TerminalFormatter
@@ -11,7 +15,7 @@ from typing_extensions import Optional, Tuple
11
15
 
12
16
  from ..datastructures.callable_expression import CallableExpression, parse_string_to_expression
13
17
  from ..datastructures.dataclasses import CaseQuery
14
- from ..datastructures.enums import PromptFor, InteractionMode
18
+ from ..datastructures.enums import PromptFor
15
19
  from .gui import RDRCaseViewer
16
20
  from .ipython_custom_shell import IPythonShell
17
21
  from ..utils import make_list
@@ -90,7 +94,7 @@ class UserPrompt:
90
94
  prompt_str = f"Give conditions on when can the rule be evaluated for:"
91
95
  case_query.scope.update({'case': case_query.case})
92
96
  shell = None
93
- if QApplication.instance() is None:
97
+ if self.viewer is None:
94
98
  prompt_str = self.construct_prompt_str_for_shell(case_query, prompt_for, prompt_str)
95
99
  shell = IPythonShell(header=prompt_str, prompt_for=prompt_for, case_query=case_query,
96
100
  code_to_modify=code_to_modify)
@@ -891,8 +891,8 @@ class SubclassJSONSerializer:
891
891
  if not filename.endswith(".json"):
892
892
  filename += ".json"
893
893
  with open(filename, "r") as f:
894
- scrdr_json = json.load(f)
895
- deserialized_obj = cls.from_json(scrdr_json)
894
+ rdr_json = json.load(f)
895
+ deserialized_obj = cls.from_json(rdr_json)
896
896
  cls.data_class_refs.clear()
897
897
  return deserialized_obj
898
898
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.4.81
3
+ Version: 0.4.83
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
@@ -3,10 +3,10 @@ ripple_down_rules/datasets.py,sha256=fJbZ7V-UUYTu5XVVpFinTbuzN3YePCnUB01L3AyZVM8
3
3
  ripple_down_rules/experts.py,sha256=dEZKv58sdicDByj0T0bu0q6coIBMce6o4t9gJICQy1k,6556
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=jxMvkyQ_2jdyxa5aKmvGRHvD-IJBKjsyOpxvvJbFLPE,45518
6
+ ripple_down_rules/rdr.py,sha256=HpvRpg_cenoJGzYeF_5xlYriWOb0xKQjpbeDyHJNeRg,45389
7
7
  ripple_down_rules/rdr_decorators.py,sha256=VdmE0JrE8j89b6Af1R1tLZiKfy3h1VCvhAUefN_FLLQ,6753
8
8
  ripple_down_rules/rules.py,sha256=7NB8qWW7XEB45tmJRYsKJqBG8DN3v02fzAFYmOkX8ow,17458
9
- ripple_down_rules/utils.py,sha256=I3QttwfI3q5JkwWgTPqCmY1G7EGDQWR3yDZPX5OAwBs,49379
9
+ ripple_down_rules/utils.py,sha256=5dpkujZDj6vjOpl4dCrhAF30xFABwSCleFrioVxgjs8,49375
10
10
  ripple_down_rules/datastructures/__init__.py,sha256=V2aNgf5C96Y5-IGghra3n9uiefpoIm_QdT7cc_C8cxQ,111
11
11
  ripple_down_rules/datastructures/callable_expression.py,sha256=jA7424_mWPbOoPICW3eLMX0-ypxnsW6gOqxrJ7JpDbE,11610
12
12
  ripple_down_rules/datastructures/case.py,sha256=oC8OSdhXvHE-Zx1IIQlad-fsKzQQqr6MZBW24c-dbeU,15191
@@ -16,10 +16,10 @@ ripple_down_rules/user_interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRk
16
16
  ripple_down_rules/user_interface/gui.py,sha256=mzkyFs0Z7iS22WpPnCwT7HVQYkB72fy8EifXTTYLEf4,27917
17
17
  ripple_down_rules/user_interface/ipython_custom_shell.py,sha256=XS3URpfoGCYA__fKOo2AmJ7wQerp7UXKdhdDKiL5gDY,6537
18
18
  ripple_down_rules/user_interface/object_diagram.py,sha256=84JlEH0nQmtGmP8Su5iRX3ZfqByYHbVwd0BQYYPuckY,4436
19
- ripple_down_rules/user_interface/prompt.py,sha256=97s5mhmsqrFTQkfmHssYFko0SPLBDxesHoLumqZO0FA,8028
19
+ ripple_down_rules/user_interface/prompt.py,sha256=9QViZOL8kfwSKXb6A_Fr9hkGGgKg12tdFOizvAN0N-4,8053
20
20
  ripple_down_rules/user_interface/template_file_creator.py,sha256=-0L0jGW1VTrL0aer67mIdjFr3gKjXKA6zRZ5IXbY5vY,13959
21
- ripple_down_rules-0.4.81.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
22
- ripple_down_rules-0.4.81.dist-info/METADATA,sha256=M5ZHi5jmF3gsqEkVreXX3HEHqhPRPmrXcFHzdXzIVkM,43218
23
- ripple_down_rules-0.4.81.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
24
- ripple_down_rules-0.4.81.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
25
- ripple_down_rules-0.4.81.dist-info/RECORD,,
21
+ ripple_down_rules-0.4.83.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
22
+ ripple_down_rules-0.4.83.dist-info/METADATA,sha256=GE3bwcxMmoJd2cOUoGOTD2w3DnQiJzsF6xR64aUuEEo,43218
23
+ ripple_down_rules-0.4.83.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
24
+ ripple_down_rules-0.4.83.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
25
+ ripple_down_rules-0.4.83.dist-info/RECORD,,