cbrkit 0.3.1__tar.gz → 0.3.2__tar.gz
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.
- {cbrkit-0.3.1 → cbrkit-0.3.2}/PKG-INFO +30 -3
- {cbrkit-0.3.1 → cbrkit-0.3.2}/README.md +29 -2
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/__init__.py +5 -3
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/_aggregate.py +1 -1
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/_attribute_value.py +1 -1
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/graph/_astar.py +1 -1
- cbrkit-0.3.1/cbrkit/sim/_helpers.py → cbrkit-0.3.2/cbrkit/helpers.py +33 -1
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/retrieval.py +1 -1
- cbrkit-0.3.2/cbrkit/sim/__init__.py +9 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/sim/collections.py +1 -1
- {cbrkit-0.3.1 → cbrkit-0.3.2}/pyproject.toml +1 -1
- cbrkit-0.3.1/cbrkit/sim/__init__.py +0 -16
- {cbrkit-0.3.1 → cbrkit-0.3.2}/LICENSE +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/__main__.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/api.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/cli.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/__init__.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/graph/__init__.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/global_sim/graph/_model.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/loaders.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/py.typed +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/sim/generic.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/sim/numeric.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/sim/strings.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/sim/taxonomy.py +0 -0
- {cbrkit-0.3.1 → cbrkit-0.3.2}/cbrkit/typing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cbrkit
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Customizable Case-Based Reasoning (CBR) toolkit for Python with a built-in API and CLI.
|
|
5
5
|
Home-page: https://wi2trier.github.io/cbrkit/
|
|
6
6
|
License: MIT
|
|
@@ -104,7 +104,7 @@ The following modules are part of CBRkit:
|
|
|
104
104
|
CBRkit is fully typed, so IDEs like VSCode and PyCharm can provide autocompletion and type checking.
|
|
105
105
|
We will explain all modules and their basic usage in the following sections.
|
|
106
106
|
|
|
107
|
-
### Loading Cases
|
|
107
|
+
### Loading Cases and Queries
|
|
108
108
|
|
|
109
109
|
The first step is to load cases and queries.
|
|
110
110
|
We provide predefined functions for the most common formats like CSV, JSON, and XML.
|
|
@@ -119,9 +119,36 @@ df = pd.read_csv("path/to/cases.csv")
|
|
|
119
119
|
cases = cbrkit.loaders.dataframe(df)
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
When dealing with formats like JSON, the files can be loaded directly:
|
|
123
123
|
|
|
124
124
|
```python
|
|
125
|
+
cases = cbrkit.loaders.json("path/to/cases.json")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Queries can either be loaded using the same loader functions.
|
|
129
|
+
CBRkit expects the type of the queries to match the type of the cases.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
# for pandas
|
|
125
133
|
queries = cbrkit.loaders.dataframe(pd.read_csv("path/to/queries.csv"))
|
|
134
|
+
# for json
|
|
135
|
+
queries = cbrkit.loaders.json("path/to/queries.json")
|
|
126
136
|
```
|
|
127
137
|
|
|
138
|
+
In case your query collection only contains a single query, you can use the `singleton` function to extract it.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
query = cbrkit.singleton(queries)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Alternatively, you can also create a query directly in Python:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# for pandas
|
|
148
|
+
query = pd.Series({"name": "John", "age": 25})
|
|
149
|
+
# for json
|
|
150
|
+
query = {"name": "John", "age": 25}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Similarity Measures and Aggregation
|
|
154
|
+
|
|
@@ -55,7 +55,7 @@ The following modules are part of CBRkit:
|
|
|
55
55
|
CBRkit is fully typed, so IDEs like VSCode and PyCharm can provide autocompletion and type checking.
|
|
56
56
|
We will explain all modules and their basic usage in the following sections.
|
|
57
57
|
|
|
58
|
-
### Loading Cases
|
|
58
|
+
### Loading Cases and Queries
|
|
59
59
|
|
|
60
60
|
The first step is to load cases and queries.
|
|
61
61
|
We provide predefined functions for the most common formats like CSV, JSON, and XML.
|
|
@@ -70,8 +70,35 @@ df = pd.read_csv("path/to/cases.csv")
|
|
|
70
70
|
cases = cbrkit.loaders.dataframe(df)
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
When dealing with formats like JSON, the files can be loaded directly:
|
|
74
74
|
|
|
75
75
|
```python
|
|
76
|
+
cases = cbrkit.loaders.json("path/to/cases.json")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Queries can either be loaded using the same loader functions.
|
|
80
|
+
CBRkit expects the type of the queries to match the type of the cases.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# for pandas
|
|
76
84
|
queries = cbrkit.loaders.dataframe(pd.read_csv("path/to/queries.csv"))
|
|
85
|
+
# for json
|
|
86
|
+
queries = cbrkit.loaders.json("path/to/queries.json")
|
|
77
87
|
```
|
|
88
|
+
|
|
89
|
+
In case your query collection only contains a single query, you can use the `singleton` function to extract it.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
query = cbrkit.singleton(queries)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Alternatively, you can also create a query directly in Python:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# for pandas
|
|
99
|
+
query = pd.Series({"name": "John", "age": 25})
|
|
100
|
+
# for json
|
|
101
|
+
query = {"name": "John", "age": 25}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Similarity Measures and Aggregation
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from . import global_sim, loaders, retrieval, sim, typing
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
from . import global_sim, helpers, loaders, retrieval, sim, typing
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
11
12
|
"loaders",
|
|
12
13
|
"sim",
|
|
13
14
|
"global_sim",
|
|
14
15
|
"typing",
|
|
15
16
|
"retrieval",
|
|
16
|
-
|
|
17
|
+
"helpers",
|
|
18
|
+
]
|
|
@@ -16,7 +16,7 @@ from cbrkit.global_sim.graph._model import (
|
|
|
16
16
|
NodeData,
|
|
17
17
|
NodeKey,
|
|
18
18
|
)
|
|
19
|
-
from cbrkit.
|
|
19
|
+
from cbrkit.helpers import unpack_sims
|
|
20
20
|
from cbrkit.typing import Casebase, FloatProtocol, KeyType, SimPairFunc, SimType
|
|
21
21
|
|
|
22
22
|
logger = logging.getLogger(__name__)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from abc import ABC
|
|
2
|
-
from collections.abc import Iterable, Mapping, Sequence
|
|
2
|
+
from collections.abc import Collection, Iterable, Mapping, Sequence
|
|
3
3
|
from inspect import signature as inspect_signature
|
|
4
4
|
from typing import Any, cast
|
|
5
5
|
|
|
@@ -22,9 +22,41 @@ __all__ = [
|
|
|
22
22
|
"unpack_sim",
|
|
23
23
|
"unpack_sims",
|
|
24
24
|
"AbstractFloat",
|
|
25
|
+
"singleton",
|
|
25
26
|
]
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
def singleton(x: Mapping[Any, ValueType] | Collection[ValueType]) -> ValueType:
|
|
30
|
+
"""
|
|
31
|
+
Return the only element of the input, or raise an error if there are multiple elements.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
x: The input collection or mapping.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
The only element of the input.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
>>> singleton([1])
|
|
41
|
+
1
|
|
42
|
+
>>> singleton({1: "a"})
|
|
43
|
+
'a'
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
ValueError: If the input has more than one element.
|
|
47
|
+
TypeError: If the input is not a collection or mapping.
|
|
48
|
+
"""
|
|
49
|
+
if len(x) != 1:
|
|
50
|
+
raise ValueError(f"Expected exactly one element, but got {len(x)}")
|
|
51
|
+
|
|
52
|
+
if isinstance(x, Mapping):
|
|
53
|
+
return next(iter(x.values()))
|
|
54
|
+
elif isinstance(x, Collection):
|
|
55
|
+
return next(iter(x))
|
|
56
|
+
else:
|
|
57
|
+
raise TypeError(f"Expected a Mapping or Collection, but got {type(x)}")
|
|
58
|
+
|
|
59
|
+
|
|
28
60
|
def dist2sim(distance: float) -> float:
|
|
29
61
|
"""Convert a distance to a similarity.
|
|
30
62
|
|
|
@@ -2,8 +2,8 @@ from collections.abc import Callable, Collection, Mapping, Sequence
|
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from typing import Any, Generic
|
|
4
4
|
|
|
5
|
+
from cbrkit.helpers import sim2map, unpack_sim
|
|
5
6
|
from cbrkit.loaders import python as load_python
|
|
6
|
-
from cbrkit.sim._helpers import sim2map, unpack_sim
|
|
7
7
|
from cbrkit.typing import (
|
|
8
8
|
AnySimFunc,
|
|
9
9
|
Casebase,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from . import collections, generic, numeric, strings, taxonomy
|
|
2
|
-
from ._helpers import AbstractFloat, dist2sim, sim2map, sim2seq, unpack_sim, unpack_sims
|
|
3
|
-
|
|
4
|
-
__all__ = [
|
|
5
|
-
"collections",
|
|
6
|
-
"generic",
|
|
7
|
-
"numeric",
|
|
8
|
-
"strings",
|
|
9
|
-
"taxonomy",
|
|
10
|
-
"dist2sim",
|
|
11
|
-
"sim2map",
|
|
12
|
-
"sim2seq",
|
|
13
|
-
"unpack_sim",
|
|
14
|
-
"unpack_sims",
|
|
15
|
-
"AbstractFloat",
|
|
16
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|