cbrkit 0.6.1__tar.gz → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cbrkit
3
- Version: 0.6.1
3
+ Version: 0.6.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
@@ -41,9 +41,9 @@ Requires-Dist: sentence-transformers (>=2.2,<3.0) ; extra == "all" or extra == "
41
41
  Requires-Dist: spacy (>=3.7,<4.0) ; extra == "all" or extra == "all" or extra == "nlp"
42
42
  Requires-Dist: torch (>=2.1.1,<3.0.0) ; extra == "all" or extra == "transformers"
43
43
  Requires-Dist: transformers (>=4.35,<5.0) ; extra == "all" or extra == "transformers"
44
- Requires-Dist: typer[all] (>=0.9,<0.10) ; extra == "all" or extra == "cli"
44
+ Requires-Dist: typer[all] (>=0.9,<1.0) ; extra == "all" or extra == "cli"
45
45
  Requires-Dist: uvicorn[standard] (>=0.24,<1.0) ; extra == "all" or extra == "api"
46
- Requires-Dist: xmltodict (>=0.13,<0.14)
46
+ Requires-Dist: xmltodict (>=0.13,<1.0)
47
47
  Project-URL: Repository, https://github.com/wi2trier/cbrkit
48
48
  Description-Content-Type: text/markdown
49
49
 
@@ -97,7 +97,12 @@ def sim2seq(
97
97
 
98
98
  return wrapped_func
99
99
 
100
- return cast(SimSeqFunc[ValueType, SimType], func)
100
+ elif len(signature.parameters) == 1:
101
+ return cast(SimSeqFunc[ValueType, SimType], func)
102
+
103
+ raise TypeError(
104
+ f"Invalid signature for similarity function: {signature.parameters}"
105
+ )
101
106
 
102
107
 
103
108
  def sim2map(
@@ -107,7 +112,13 @@ def sim2map(
107
112
  ) -> SimMapFunc[KeyType, ValueType, SimType]:
108
113
  signature = inspect_signature(func)
109
114
 
110
- if len(signature.parameters) == 2 and signature.parameters.keys() == {"x", "y"}:
115
+ if len(signature.parameters) == 2 and signature.parameters.keys() in (
116
+ {"x_map", "y"},
117
+ {"casebase", "query"},
118
+ ):
119
+ return cast(SimMapFunc[KeyType, ValueType, SimType], func)
120
+
121
+ elif len(signature.parameters) == 2:
111
122
  sim_pair_func = cast(SimPairFunc[ValueType, SimType], func)
112
123
 
113
124
  def wrapped_sim_pair_func(
@@ -131,7 +142,9 @@ def sim2map(
131
142
 
132
143
  return wrapped_sim_seq_func
133
144
 
134
- return cast(SimMapFunc[KeyType, ValueType, SimType], func)
145
+ raise TypeError(
146
+ f"Invalid signature for similarity function: {signature.parameters}"
147
+ )
135
148
 
136
149
 
137
150
  def unpack_sim(sim: AnyFloat) -> float:
@@ -8,8 +8,8 @@ from cbrkit.typing import (
8
8
  AnySimFunc,
9
9
  Casebase,
10
10
  KeyType,
11
- RetrieveFunc,
12
11
  SimMap,
12
+ SimMapFunc,
13
13
  SimType,
14
14
  ValueType,
15
15
  )
@@ -76,8 +76,8 @@ class Result(Generic[KeyType, ValueType, SimType]):
76
76
  def apply(
77
77
  casebase: Casebase[KeyType, ValueType],
78
78
  query: ValueType,
79
- retrievers: RetrieveFunc[KeyType, ValueType, SimType]
80
- | Sequence[RetrieveFunc[KeyType, ValueType, SimType]],
79
+ retrievers: SimMapFunc[KeyType, ValueType, SimType]
80
+ | Sequence[SimMapFunc[KeyType, ValueType, SimType]],
81
81
  ) -> Result[KeyType, ValueType, SimType]:
82
82
  """Applies a query to a Casebase using retriever functions.
83
83
 
@@ -135,7 +135,7 @@ def build(
135
135
  limit: int | None = None,
136
136
  min_similarity: float | None = None,
137
137
  max_similarity: float | None = None,
138
- ) -> RetrieveFunc[KeyType, ValueType, SimType]:
138
+ ) -> SimMapFunc[KeyType, ValueType, SimType]:
139
139
  """Based on the similarity function this function creates a retriever function.
140
140
 
141
141
  The given limit will be applied after filtering for min/max similarity.
@@ -174,10 +174,10 @@ def build(
174
174
  sim_func = sim2map(similarity_func)
175
175
 
176
176
  def wrapped_func(
177
- casebase: Casebase[KeyType, ValueType],
178
- query: ValueType,
177
+ x_map: Casebase[KeyType, ValueType],
178
+ y: ValueType,
179
179
  ) -> SimMap[KeyType, SimType]:
180
- similarities = sim_func(casebase, query)
180
+ similarities = sim_func(x_map, y)
181
181
  ranking = _similarities2ranking(similarities)
182
182
 
183
183
  if min_similarity is not None:
@@ -200,11 +200,11 @@ def build(
200
200
 
201
201
  def load(
202
202
  import_names: Sequence[str] | str,
203
- ) -> list[RetrieveFunc[Any, Any, Any]]:
203
+ ) -> list[SimMapFunc[Any, Any, Any]]:
204
204
  if isinstance(import_names, str):
205
205
  import_names = [import_names]
206
206
 
207
- retrievers: list[RetrieveFunc] = []
207
+ retrievers: list[SimMapFunc] = []
208
208
 
209
209
  for import_path in import_names:
210
210
  obj = load_python(import_path)
@@ -220,11 +220,11 @@ def load(
220
220
 
221
221
  def load_map(
222
222
  import_names: Collection[str] | str,
223
- ) -> dict[str, RetrieveFunc[Any, Any, Any]]:
223
+ ) -> dict[str, SimMapFunc[Any, Any, Any]]:
224
224
  if isinstance(import_names, str):
225
225
  import_names = [import_names]
226
226
 
227
- retrievers: dict[str, RetrieveFunc] = {}
227
+ retrievers: dict[str, SimMapFunc] = {}
228
228
 
229
229
  for import_path in import_names:
230
230
  obj = load_python(import_path)
@@ -28,9 +28,10 @@ SimSeq = Sequence[SimType]
28
28
  SimSeqOrMap = SimMap[KeyType, SimType] | SimSeq[SimType]
29
29
 
30
30
 
31
+ # Parameter names must match so that the signature can be inspected, do not add `/` here!
31
32
  class SimMapFunc(Protocol[KeyType, ValueType_contra, SimType_cov]):
32
33
  def __call__(
33
- self, x_map: Mapping[KeyType, ValueType_contra], y: ValueType_contra, /
34
+ self, x_map: Mapping[KeyType, ValueType_contra], y: ValueType_contra
34
35
  ) -> SimMap[KeyType, SimType_cov]:
35
36
  ...
36
37
 
@@ -42,9 +43,8 @@ class SimSeqFunc(Protocol[ValueType_contra, SimType_cov]):
42
43
  ...
43
44
 
44
45
 
45
- # Parameter names must match so that the signature can be inspected, do not add `/` here!
46
46
  class SimPairFunc(Protocol[ValueType_contra, SimType_cov]):
47
- def __call__(self, x: ValueType_contra, y: ValueType_contra) -> SimType_cov:
47
+ def __call__(self, x: ValueType_contra, y: ValueType_contra, /) -> SimType_cov:
48
48
  ...
49
49
 
50
50
 
@@ -54,8 +54,6 @@ AnySimFunc = (
54
54
  | SimPairFunc[ValueType, SimType]
55
55
  )
56
56
 
57
- RetrieveFunc = SimMapFunc[KeyType, ValueType, SimType]
58
-
59
57
 
60
58
  class AggregatorFunc(Protocol[KeyType, SimType_contra]):
61
59
  def __call__(
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cbrkit"
3
- version = "0.6.1"
3
+ version = "0.6.2"
4
4
  description = "Customizable Case-Based Reasoning (CBR) toolkit for Python with a built-in API and CLI."
5
5
  authors = ["Mirko Lenz <mirko@mirkolenz.com>"]
6
6
  license = "MIT"
@@ -52,13 +52,13 @@ sentence-transformers = { version = "^2.2", optional = true }
52
52
  spacy = { version = "^3.7", optional = true }
53
53
  torch = { version = "^2.1.1", optional = true }
54
54
  transformers = { version = "^4.35", optional = true }
55
- typer = { version = "^0.9", extras = ["all"], optional = true }
55
+ typer = { version = ">=0.9, <1.0", extras = ["all"], optional = true }
56
56
  uvicorn = { version = ">=0.24, <1.0", optional = true, extras = ["standard"] }
57
- xmltodict = "^0.13"
57
+ xmltodict = ">=0.13, <1.0"
58
58
 
59
59
  [tool.poetry.group.dev.dependencies]
60
60
  pytest = "^8.0.0"
61
- pytest-cov = "^4.1"
61
+ pytest-cov = "^5.0.0"
62
62
 
63
63
  [tool.poetry.group.docs.dependencies]
64
64
  pdoc = "^14.4"
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