pairwise-comparison-framework 1.0.0__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.
@@ -0,0 +1,4 @@
1
+ from .clusterizer import Clusterizer
2
+ from .predictor import Predictor
3
+
4
+ __all__ = ["Clusterizer", "Predictor"]
@@ -0,0 +1,59 @@
1
+ import json
2
+
3
+ from .models import ItemLabel, UserComparisons
4
+
5
+
6
+ class BaseDataLoader:
7
+ """Shared data-loading logic for classes that consume comparison data.
8
+
9
+ Provides `_load_comparisons` and `_load_labels` together with the
10
+ `comparisons` and `labels` attributes they populate. Subclasses
11
+ should call `super().__init__()` and then perform their own
12
+ initialisation.
13
+ """
14
+
15
+ comparisons: list[UserComparisons]
16
+ labels: list[ItemLabel]
17
+
18
+ def __init__(self) -> None:
19
+ self.comparisons = []
20
+ self.labels = []
21
+
22
+ def _load_comparisons(self, filename: str) -> None:
23
+ """Load pairwise comparisons from a JSON file.
24
+
25
+ The file must contain a JSON array of objects, each with a
26
+ `user_id` and a `comparisons` list.
27
+
28
+ Args:
29
+ filename: Path to the JSON file.
30
+ """
31
+ with open(filename, "r") as f:
32
+ data = json.load(f)
33
+
34
+ if not isinstance(data, list):
35
+ raise ValueError("comparisons must be a list")
36
+
37
+ self.comparisons = [UserComparisons(**item) for item in data]
38
+
39
+ print(f"Loaded pairwise comparisons from {len(self.comparisons)} users")
40
+ print(
41
+ f"Total amount of pairwise comparisons: "
42
+ f"{sum(len(user.comparisons) for user in self.comparisons)}"
43
+ )
44
+
45
+ def _load_labels(self, filename: str) -> None:
46
+ """Load item labels from a JSON file.
47
+
48
+ Args:
49
+ filename: Path to the JSON file containing a list of
50
+ `{"item_id": ..., "label": ...}` objects.
51
+ """
52
+ with open(filename, "r") as f:
53
+ data = json.load(f)
54
+
55
+ if not isinstance(data, list):
56
+ raise ValueError("labels must be a list")
57
+
58
+ self.labels = [ItemLabel(**item) for item in data]
59
+ print(f"Loaded labels from {len(self.labels)} items")