ripple-down-rules 0.0.7__py3-none-any.whl → 0.0.8__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
@@ -128,8 +128,6 @@ class RippleDownRules(ABC):
128
128
  target = target if is_iterable(target) else [target]
129
129
  recall = [not yi or (yi in pred_cat) for yi in target]
130
130
  target_types = [type(yi) for yi in target]
131
- if len(pred_cat) > 1:
132
- print(pred_cat)
133
131
  precision = [(pred in target) or (type(pred) not in target_types) for pred in pred_cat]
134
132
  return precision, recall
135
133
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import importlib
4
+ import json
4
5
  import logging
5
6
  from abc import abstractmethod
6
7
  from collections import UserDict
@@ -81,6 +82,18 @@ class SubclassJSONSerializer:
81
82
  'from_json' method.
82
83
  """
83
84
 
85
+ def to_json_file(self, filename: str):
86
+ """
87
+ Save the object to a json file.
88
+ """
89
+ data = self.to_json()
90
+ # save the json to a file
91
+ if not filename.endswith(".json"):
92
+ filename += ".json"
93
+ with open(filename, "w") as f:
94
+ json.dump(data, f, indent=4)
95
+ return data
96
+
84
97
  def to_json(self) -> Dict[str, Any]:
85
98
  return {"_type": get_full_class_name(self.__class__), **self._to_json()}
86
99
 
@@ -104,6 +117,19 @@ class SubclassJSONSerializer:
104
117
  """
105
118
  raise NotImplementedError()
106
119
 
120
+ @classmethod
121
+ def from_json_file(cls, filename: str):
122
+ """
123
+ Create an instance of the subclass from the data in the given json file.
124
+
125
+ :param filename: The filename of the json file.
126
+ """
127
+ if not filename.endswith(".json"):
128
+ filename += ".json"
129
+ with open(filename, "r") as f:
130
+ scrdr_json = json.load(f)
131
+ return cls.from_json(scrdr_json)
132
+
107
133
  @classmethod
108
134
  def from_json(cls, data: Dict[str, Any]) -> Self:
109
135
  """
@@ -124,6 +150,9 @@ class SubclassJSONSerializer:
124
150
 
125
151
  raise ValueError("Unknown type {}".format(data["_type"]))
126
152
 
153
+ save = to_json_file
154
+ load = from_json_file
155
+
127
156
 
128
157
  def copy_case(case: Union[Case, SQLTable]) -> Union[Case, SQLTable]:
129
158
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.0.7
3
+ Version: 0.0.8
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,16 +3,16 @@ ripple_down_rules/datasets.py,sha256=p7WmLiAKcYtzLq87RJhzU_BHCdM-zKK71yldjyYNpUE
3
3
  ripple_down_rules/experts.py,sha256=ajH46NXM6IREtWr2a-ZBxdKl4CFzSx5S7yktnyXgwnc,11089
4
4
  ripple_down_rules/failures.py,sha256=E6ajDUsw3Blom8eVLbA7d_Qnov2conhtZ0UmpQ9ZtSE,302
5
5
  ripple_down_rules/prompt.py,sha256=lmREZRyleBTHrVtcf2j_48oc0v3VlxXYGhl6w1mk8qI,4208
6
- ripple_down_rules/rdr.py,sha256=dS_OqaGtP1PAKEe0h-dMy7JI9ycNuH_EIbHlh-Nz4Sg,34189
6
+ ripple_down_rules/rdr.py,sha256=Jag1zq4UqCIJGL_DhLcbYu6l7Bvkskay-mnJ5KRF34g,34131
7
7
  ripple_down_rules/rules.py,sha256=R9wIyalXBc6fGogzy92OxsyKAtJdQwdso_Vs1evWZGU,10274
8
- ripple_down_rules/utils.py,sha256=VjpdJ5W-xK-TQttfpNIHRKpYK91vYjtQ22kgccQgVTQ,17183
8
+ ripple_down_rules/utils.py,sha256=pmjIPjF9wq6dmCHCoUKFRsJmSaI0b-hRLn375WHgWgQ,18010
9
9
  ripple_down_rules/datastructures/__init__.py,sha256=wY9WqXavuE3wQ1YP65cs_SZyr7CEMB9tol-4oxgK9CM,104
10
10
  ripple_down_rules/datastructures/callable_expression.py,sha256=lF8ag3-8oYuETAUohtRfviOpypSMQR-JEJGgR0Zhv3E,9055
11
11
  ripple_down_rules/datastructures/dataclasses.py,sha256=FW3MMhGXTPa0XwIyLzGalrPwiltNeUqbGIawCAKDHGk,2448
12
12
  ripple_down_rules/datastructures/enums.py,sha256=l0Eu-TeJ6qB2XHoJycXmUgLw-3yUebQ8SsEbW8bBZdM,4543
13
13
  ripple_down_rules/datastructures/table.py,sha256=G2ShfPmyiwfDXS-JY_jFD6nOx7OLuMr-GP--OCDGKYc,13733
14
- ripple_down_rules-0.0.7.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
15
- ripple_down_rules-0.0.7.dist-info/METADATA,sha256=fBb_rMvpmfAueLPCXvNs3IXLNX-COunhRnEq7iYkV5Y,42518
16
- ripple_down_rules-0.0.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
17
- ripple_down_rules-0.0.7.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
18
- ripple_down_rules-0.0.7.dist-info/RECORD,,
14
+ ripple_down_rules-0.0.8.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
15
+ ripple_down_rules-0.0.8.dist-info/METADATA,sha256=8uoMHOwdTv7D_NqbYZbvFGw7Awn5rn0xTHf_B43hNsw,42518
16
+ ripple_down_rules-0.0.8.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
17
+ ripple_down_rules-0.0.8.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
18
+ ripple_down_rules-0.0.8.dist-info/RECORD,,