cbrkit 0.12.0__tar.gz → 0.12.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.12.0
3
+ Version: 0.12.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
@@ -23,13 +23,13 @@ retriever = []
23
23
  retriever_map = {}
24
24
 
25
25
  if settings.retriever is not None and settings.retriever_map is not None:
26
- retriever = cbrkit.retrieval.load(settings.retriever)
27
- retriever_map = cbrkit.retrieval.load_map(settings.retriever_map)
26
+ retriever = cbrkit.retrieval.load(settings.retriever.split(","))
27
+ retriever_map = cbrkit.retrieval.load_map(settings.retriever_map.split(","))
28
28
  elif settings.retriever is not None:
29
- retriever = cbrkit.retrieval.load(settings.retriever)
29
+ retriever = cbrkit.retrieval.load(settings.retriever.split(","))
30
30
  retriever_map = {str(idx): retriever for idx, retriever in enumerate(retriever)}
31
31
  elif settings.retriever_map is not None:
32
- retriever_map = cbrkit.retrieval.load_map(settings.retriever_map)
32
+ retriever_map = cbrkit.retrieval.load_map(settings.retriever_map.split(","))
33
33
  retriever = list(retriever_map.values())
34
34
 
35
35
 
@@ -3,11 +3,13 @@
3
3
  """
4
4
 
5
5
  import os
6
+ import sys
6
7
  from pathlib import Path
8
+ from typing import Annotated
7
9
 
8
10
  try:
11
+ import typer
9
12
  from rich import print
10
- from typer import Typer
11
13
  except ModuleNotFoundError:
12
14
  print(
13
15
  "Please install cbrkit with the [cli] extra to use the command line interface."
@@ -16,7 +18,7 @@ except ModuleNotFoundError:
16
18
 
17
19
  import cbrkit
18
20
 
19
- app = Typer()
21
+ app = typer.Typer()
20
22
 
21
23
 
22
24
  @app.callback()
@@ -25,27 +27,45 @@ def app_callback():
25
27
 
26
28
 
27
29
  @app.command()
28
- def retrieve(casebase_path: Path, queries_path: Path, retriever: str):
30
+ def retrieve(
31
+ casebase_path: Path,
32
+ queries_path: Path,
33
+ retriever: str,
34
+ print_ranking: bool = True,
35
+ ) -> None:
29
36
  casebase = cbrkit.loaders.path(casebase_path)
30
37
  queries = cbrkit.loaders.path(queries_path)
31
38
  retrievers = cbrkit.retrieval.load(retriever)
32
39
 
33
40
  for query_name, query in queries.items():
34
41
  result = cbrkit.retrieval.apply(casebase, query, retrievers)
35
- print(f"Query: {query_name}")
36
- print(result.ranking)
37
- print()
42
+
43
+ if print_ranking:
44
+ print(f"Query: {query_name}")
45
+ print(result.ranking)
46
+ print()
38
47
 
39
48
 
40
49
  @app.command()
41
- def serve(retriever: str, reload: bool = False) -> None:
50
+ def serve(
51
+ retriever: list[str],
52
+ search_path: Annotated[list[Path], typer.Option(default_factory=list)],
53
+ host: str = "0.0.0.0",
54
+ port: int = 8080,
55
+ reload: bool = False,
56
+ root_path: str = "",
57
+ ) -> None:
42
58
  import uvicorn
43
59
 
44
- os.environ["CBRKIT_RETRIEVER"] = retriever
60
+ sys.path.extend(str(x) for x in search_path)
61
+ os.environ["CBRKIT_RETRIEVER"] = ",".join(retriever)
45
62
 
46
63
  uvicorn.run(
47
64
  "cbrkit.api:app",
65
+ host=host,
66
+ port=port,
48
67
  reload=reload,
68
+ root_path=root_path,
49
69
  )
50
70
 
51
71
 
@@ -70,7 +70,7 @@ class DataFrameCasebase(abc.Mapping):
70
70
  if isinstance(key, int):
71
71
  return self.df.iloc[key]
72
72
  elif isinstance(key, str):
73
- return self.df.loc[key]
73
+ return cast(Series, self.df.loc[key])
74
74
 
75
75
  raise TypeError(f"Invalid key type: {type(key)}")
76
76
 
@@ -68,7 +68,7 @@ def aggregator(
68
68
  pooling_func = _pooling_funcs[pooling] if isinstance(pooling, str) else pooling
69
69
 
70
70
  def wrapped_func(similarities: SimSeqOrMap[KeyType, AnyFloat]) -> float:
71
- assert pooling_weights is None or type(similarities) == type(pooling_weights)
71
+ assert pooling_weights is None or type(similarities) is type(pooling_weights)
72
72
 
73
73
  sims: Sequence[float] # noqa: F821
74
74
 
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Callable, Collection, Sequence, Set
2
2
  from dataclasses import dataclass, field
3
3
  from itertools import product
4
- from typing import Any, Generic
4
+ from typing import Any, Generic, cast
5
5
 
6
6
  from cbrkit.helpers import dist2sim, unpack_sim
7
7
  from cbrkit.typing import FloatProtocol, SimPairFunc, SimType, ValueType
@@ -52,7 +52,7 @@ def smith_waterman(
52
52
 
53
53
  def wrapped_func(x: Sequence[ValueType], y: Sequence[ValueType]) -> float:
54
54
  try:
55
- alignment = smith.SmithWaterman(x, y)
55
+ alignment = smith.SmithWaterman(cast(Sequence, x), cast(Sequence, y))
56
56
  alignment.change_matrix(
57
57
  core.ScoreMatrix(
58
58
  match=match_score, miss=mismatch_penalty, gap=gap_penalty
@@ -72,7 +72,7 @@ class GraphMapping(Generic[GraphData, NodeKey, NodeData, EdgeKey, EdgeData]):
72
72
  def is_legal_node_mapping(self, x: NodeKey, y: NodeKey) -> bool:
73
73
  """Check if mapping is legal"""
74
74
 
75
- return not (self._is_node_mapped(x) or type(x) != type(y))
75
+ return not (self._is_node_mapped(x) or type(x) is not type(y))
76
76
 
77
77
  def is_legal_edge_mapping(self, x: EdgeKey, y: EdgeKey) -> bool:
78
78
  """Check if mapping is legal"""
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cbrkit"
3
- version = "0.12.0"
3
+ version = "0.12.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"
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