biblicus 0.2.0__py3-none-any.whl → 0.3.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.
- biblicus/__init__.py +2 -2
- biblicus/_vendor/dotyaml/__init__.py +14 -0
- biblicus/_vendor/dotyaml/interpolation.py +63 -0
- biblicus/_vendor/dotyaml/loader.py +181 -0
- biblicus/_vendor/dotyaml/transformer.py +135 -0
- biblicus/backends/__init__.py +0 -2
- biblicus/backends/base.py +3 -3
- biblicus/backends/scan.py +21 -15
- biblicus/backends/sqlite_full_text_search.py +14 -15
- biblicus/cli.py +33 -49
- biblicus/corpus.py +39 -58
- biblicus/errors.py +15 -0
- biblicus/evaluation.py +4 -8
- biblicus/extraction.py +276 -77
- biblicus/extractors/__init__.py +14 -3
- biblicus/extractors/base.py +12 -5
- biblicus/extractors/metadata_text.py +13 -5
- biblicus/extractors/openai_stt.py +180 -0
- biblicus/extractors/pass_through_text.py +16 -6
- biblicus/extractors/pdf_text.py +100 -0
- biblicus/extractors/pipeline.py +105 -0
- biblicus/extractors/rapidocr_text.py +129 -0
- biblicus/extractors/select_longest_text.py +105 -0
- biblicus/extractors/select_text.py +100 -0
- biblicus/extractors/unstructured_text.py +100 -0
- biblicus/frontmatter.py +0 -3
- biblicus/hook_logging.py +0 -5
- biblicus/hook_manager.py +3 -5
- biblicus/hooks.py +3 -7
- biblicus/ignore.py +0 -3
- biblicus/models.py +87 -0
- biblicus/retrieval.py +0 -4
- biblicus/sources.py +44 -9
- biblicus/time.py +0 -1
- biblicus/uris.py +3 -4
- biblicus/user_config.py +138 -0
- {biblicus-0.2.0.dist-info → biblicus-0.3.0.dist-info}/METADATA +78 -16
- biblicus-0.3.0.dist-info/RECORD +44 -0
- biblicus/extractors/cascade.py +0 -101
- biblicus-0.2.0.dist-info/RECORD +0 -32
- {biblicus-0.2.0.dist-info → biblicus-0.3.0.dist-info}/WHEEL +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.3.0.dist-info}/entry_points.txt +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {biblicus-0.2.0.dist-info → biblicus-0.3.0.dist-info}/top_level.txt +0 -0
biblicus/user_config.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""
|
|
2
|
+
User configuration file loading for Biblicus.
|
|
3
|
+
|
|
4
|
+
User configuration is intended for small, local settings such as credentials for optional
|
|
5
|
+
integrations. It is separate from corpus configuration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Dict, Optional
|
|
13
|
+
|
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
15
|
+
|
|
16
|
+
from ._vendor.dotyaml import ConfigLoader
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OpenAiUserConfig(BaseModel):
|
|
20
|
+
"""
|
|
21
|
+
Configuration for OpenAI integrations.
|
|
22
|
+
|
|
23
|
+
:ivar api_key: OpenAI API key used for authenticated requests.
|
|
24
|
+
:vartype api_key: str
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
model_config = ConfigDict(extra="forbid")
|
|
28
|
+
|
|
29
|
+
api_key: str = Field(min_length=1)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BiblicusUserConfig(BaseModel):
|
|
33
|
+
"""
|
|
34
|
+
Parsed user configuration for Biblicus.
|
|
35
|
+
|
|
36
|
+
:ivar openai: Optional OpenAI configuration.
|
|
37
|
+
:vartype openai: OpenAiUserConfig or None
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
model_config = ConfigDict(extra="forbid")
|
|
41
|
+
|
|
42
|
+
openai: Optional[OpenAiUserConfig] = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def default_user_config_paths(
|
|
46
|
+
*, cwd: Optional[Path] = None, home: Optional[Path] = None
|
|
47
|
+
) -> list[Path]:
|
|
48
|
+
"""
|
|
49
|
+
Compute the default user configuration file search paths.
|
|
50
|
+
|
|
51
|
+
The search order is:
|
|
52
|
+
|
|
53
|
+
1. Home configuration: ``~/.biblicus/config.yml``
|
|
54
|
+
2. Local configuration: ``./.biblicus/config.yml``
|
|
55
|
+
|
|
56
|
+
Local configuration overrides home configuration when both exist.
|
|
57
|
+
|
|
58
|
+
:param cwd: Optional working directory to use instead of the process current directory.
|
|
59
|
+
:type cwd: Path or None
|
|
60
|
+
:param home: Optional home directory to use instead of the current user's home directory.
|
|
61
|
+
:type home: Path or None
|
|
62
|
+
:return: Ordered list of configuration file paths.
|
|
63
|
+
:rtype: list[Path]
|
|
64
|
+
"""
|
|
65
|
+
resolved_home = (home or Path.home()).expanduser()
|
|
66
|
+
resolved_cwd = cwd or Path.cwd()
|
|
67
|
+
return [
|
|
68
|
+
resolved_home / ".biblicus" / "config.yml",
|
|
69
|
+
resolved_cwd / ".biblicus" / "config.yml",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _deep_merge(base: Dict[str, Any], override: Dict[str, Any]) -> Dict[str, Any]:
|
|
74
|
+
merged: Dict[str, Any] = {key: value for key, value in base.items()}
|
|
75
|
+
for key, value in override.items():
|
|
76
|
+
if key in merged and isinstance(merged[key], dict) and isinstance(value, dict):
|
|
77
|
+
merged[key] = _deep_merge(merged[key], value)
|
|
78
|
+
else:
|
|
79
|
+
merged[key] = value
|
|
80
|
+
return merged
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _load_dotyaml_data(path: Path) -> Dict[str, Any]:
|
|
84
|
+
"""
|
|
85
|
+
Load a dotyaml configuration file and return a nested mapping.
|
|
86
|
+
|
|
87
|
+
:param path: Configuration file path.
|
|
88
|
+
:type path: Path
|
|
89
|
+
:return: Parsed YAML data mapping.
|
|
90
|
+
:rtype: dict[str, Any]
|
|
91
|
+
"""
|
|
92
|
+
loader = ConfigLoader(prefix="", load_dotenv_first=False)
|
|
93
|
+
loaded = loader.load_from_yaml(path)
|
|
94
|
+
return loaded if isinstance(loaded, dict) else {}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def load_user_config(*, paths: Optional[list[Path]] = None) -> BiblicusUserConfig:
|
|
98
|
+
"""
|
|
99
|
+
Load user configuration from known locations.
|
|
100
|
+
|
|
101
|
+
This function merges multiple configuration files in order. Later files override earlier files.
|
|
102
|
+
|
|
103
|
+
:param paths: Optional explicit search paths. When omitted, the default paths are used.
|
|
104
|
+
:type paths: list[Path] or None
|
|
105
|
+
:return: Parsed user configuration. When no files exist, the configuration is empty.
|
|
106
|
+
:rtype: BiblicusUserConfig
|
|
107
|
+
:raises ValueError: If an existing configuration file is not parseable.
|
|
108
|
+
"""
|
|
109
|
+
search_paths = paths or default_user_config_paths()
|
|
110
|
+
merged_data: Dict[str, Any] = {}
|
|
111
|
+
|
|
112
|
+
for path in search_paths:
|
|
113
|
+
if not path.is_file():
|
|
114
|
+
continue
|
|
115
|
+
loaded = _load_dotyaml_data(path)
|
|
116
|
+
merged_data = _deep_merge(merged_data, loaded)
|
|
117
|
+
|
|
118
|
+
return BiblicusUserConfig.model_validate(merged_data)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def resolve_openai_api_key(*, config: Optional[BiblicusUserConfig] = None) -> Optional[str]:
|
|
122
|
+
"""
|
|
123
|
+
Resolve an OpenAI API key from environment or user configuration.
|
|
124
|
+
|
|
125
|
+
Environment takes precedence over configuration.
|
|
126
|
+
|
|
127
|
+
:param config: Optional pre-loaded user configuration.
|
|
128
|
+
:type config: BiblicusUserConfig or None
|
|
129
|
+
:return: API key string, or None when no key is available.
|
|
130
|
+
:rtype: str or None
|
|
131
|
+
"""
|
|
132
|
+
env_key = os.environ.get("OPENAI_API_KEY")
|
|
133
|
+
if env_key:
|
|
134
|
+
return env_key
|
|
135
|
+
loaded = config or load_user_config()
|
|
136
|
+
if loaded.openai is None:
|
|
137
|
+
return None
|
|
138
|
+
return loaded.openai.api_key
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: biblicus
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Command line interface and Python library for corpus ingestion, retrieval, and evaluation.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -8,20 +8,30 @@ Description-Content-Type: text/markdown
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: pydantic>=2.0
|
|
10
10
|
Requires-Dist: PyYAML>=6.0
|
|
11
|
+
Requires-Dist: pypdf>=4.0
|
|
11
12
|
Provides-Extra: dev
|
|
12
13
|
Requires-Dist: behave>=1.2.6; extra == "dev"
|
|
13
14
|
Requires-Dist: coverage[toml]>=7.0; extra == "dev"
|
|
14
15
|
Requires-Dist: sphinx>=7.0; extra == "dev"
|
|
15
16
|
Requires-Dist: myst-parser>=2.0; extra == "dev"
|
|
17
|
+
Requires-Dist: sphinx_rtd_theme>=2.0; extra == "dev"
|
|
16
18
|
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
17
19
|
Requires-Dist: black>=24.0; extra == "dev"
|
|
18
20
|
Requires-Dist: python-semantic-release>=9.0.0; extra == "dev"
|
|
21
|
+
Provides-Extra: openai
|
|
22
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
23
|
+
Provides-Extra: unstructured
|
|
24
|
+
Requires-Dist: unstructured>=0.12.0; extra == "unstructured"
|
|
25
|
+
Requires-Dist: python-docx>=1.1.0; extra == "unstructured"
|
|
26
|
+
Provides-Extra: ocr
|
|
27
|
+
Requires-Dist: rapidocr-onnxruntime>=1.3.0; extra == "ocr"
|
|
19
28
|
Dynamic: license-file
|
|
20
29
|
|
|
21
30
|
# Biblicus
|
|
22
31
|
|
|
23
32
|
![Continuous integration][continuous-integration-badge]
|
|
24
33
|
![Coverage][coverage-badge]
|
|
34
|
+
![Documentation][documentation-badge]
|
|
25
35
|
|
|
26
36
|
Make your documents usable by your assistant, then decide later how you will search and retrieve them.
|
|
27
37
|
|
|
@@ -31,28 +41,34 @@ The first practical problem is not retrieval. It is collection and care. You nee
|
|
|
31
41
|
|
|
32
42
|
This library gives you a corpus, which is a normal folder on disk. It stores each ingested item as a file, with optional metadata stored next to it. You can open and inspect the raw files directly. Any derived catalog or index can be rebuilt from the raw corpus.
|
|
33
43
|
|
|
34
|
-
It
|
|
44
|
+
It can be used alongside LangChain, Tactus, Pydantic AI, or the agent development kit. Use it from Python or from the command line interface.
|
|
35
45
|
|
|
36
46
|
See [retrieval augmented generation overview] for a short introduction to the idea.
|
|
37
47
|
|
|
38
|
-
##
|
|
48
|
+
## A beginner friendly mental model
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
Think in three stages.
|
|
51
|
+
|
|
52
|
+
- Ingest puts raw items into a corpus. This is file first and human inspectable.
|
|
53
|
+
- Extract turns items into usable text. This is where you would do text extraction from Portable Document Format files, optical character recognition for images, or speech to text for audio. If an item is already text, extraction can simply read it. Extraction outputs are derived artifacts, not edits to the raw files.
|
|
54
|
+
- Retrieve searches extracted text and returns evidence. Evidence is structured so you can turn it into context for your model call in whatever way your project prefers.
|
|
55
|
+
|
|
56
|
+
If you learn a few project words, the rest of the system becomes predictable.
|
|
41
57
|
|
|
42
58
|
- Corpus is the folder that holds raw items and their metadata.
|
|
43
|
-
- Item is the raw bytes
|
|
59
|
+
- Item is the raw bytes plus optional metadata and source information.
|
|
44
60
|
- Catalog is the rebuildable index of the corpus.
|
|
45
|
-
-
|
|
46
|
-
- Run is a recorded retrieval build for a corpus.
|
|
61
|
+
- Extraction run is a recorded extraction build that produces text artifacts.
|
|
47
62
|
- Backend is a pluggable retrieval implementation.
|
|
48
|
-
-
|
|
49
|
-
-
|
|
63
|
+
- Run is a recorded retrieval build for a corpus.
|
|
64
|
+
- Evidence is what retrieval returns, with identifiers and source information.
|
|
50
65
|
|
|
51
66
|
## Diagram
|
|
52
67
|
|
|
53
68
|
This diagram shows how a corpus becomes evidence for an assistant.
|
|
54
|
-
|
|
55
|
-
The
|
|
69
|
+
Extraction is introduced here as a separate stage so you can swap extraction approaches without changing the raw corpus.
|
|
70
|
+
The legend shows what the block styles mean.
|
|
71
|
+
Your code is where you decide how to turn evidence into context and how to call a model.
|
|
56
72
|
|
|
57
73
|
```mermaid
|
|
58
74
|
%%{init: {"flowchart": {"useMaxWidth": true, "nodeSpacing": 18, "rankSpacing": 22}}}%%
|
|
@@ -61,7 +77,10 @@ flowchart LR
|
|
|
61
77
|
direction LR
|
|
62
78
|
LegendArtifact[Stored artifact or evidence]
|
|
63
79
|
LegendStep[Step]
|
|
80
|
+
LegendStable[Stable region]
|
|
81
|
+
LegendPluggable[Pluggable region]
|
|
64
82
|
LegendArtifact --- LegendStep
|
|
83
|
+
LegendStable --- LegendPluggable
|
|
65
84
|
end
|
|
66
85
|
|
|
67
86
|
subgraph Main[" "]
|
|
@@ -74,12 +93,19 @@ flowchart LR
|
|
|
74
93
|
Raw --> Catalog[Catalog file]
|
|
75
94
|
end
|
|
76
95
|
|
|
96
|
+
subgraph PluggableExtractionPipeline[Pluggable extraction pipeline]
|
|
97
|
+
direction TB
|
|
98
|
+
Catalog --> Extract[Extract pipeline]
|
|
99
|
+
Extract --> ExtractedText[Extracted text artifacts]
|
|
100
|
+
ExtractedText --> ExtractionRun[Extraction run manifest]
|
|
101
|
+
end
|
|
102
|
+
|
|
77
103
|
subgraph PluggableRetrievalBackend[Pluggable retrieval backend]
|
|
78
104
|
direction LR
|
|
79
105
|
|
|
80
106
|
subgraph BackendIngestionIndexing[Ingestion and indexing]
|
|
81
107
|
direction TB
|
|
82
|
-
|
|
108
|
+
ExtractionRun --> Build[Build run]
|
|
83
109
|
Build --> BackendIndex[Backend index]
|
|
84
110
|
BackendIndex --> Run[Run manifest]
|
|
85
111
|
end
|
|
@@ -100,6 +126,7 @@ flowchart LR
|
|
|
100
126
|
end
|
|
101
127
|
|
|
102
128
|
style StableCore fill:#ffffff,stroke:#8e24aa,stroke-width:2px,color:#111111
|
|
129
|
+
style PluggableExtractionPipeline fill:#ffffff,stroke:#5e35b1,stroke-dasharray:6 3,stroke-width:2px,color:#111111
|
|
103
130
|
style PluggableRetrievalBackend fill:#ffffff,stroke:#1e88e5,stroke-dasharray:6 3,stroke-width:2px,color:#111111
|
|
104
131
|
style YourCode fill:#ffffff,stroke:#d81b60,stroke-width:2px,color:#111111
|
|
105
132
|
style BackendIngestionIndexing fill:#ffffff,stroke:#cfd8dc,color:#111111
|
|
@@ -107,6 +134,8 @@ flowchart LR
|
|
|
107
134
|
|
|
108
135
|
style Raw fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
109
136
|
style Catalog fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
137
|
+
style ExtractedText fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
138
|
+
style ExtractionRun fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
110
139
|
style BackendIndex fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
111
140
|
style Run fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
112
141
|
style Evidence fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
@@ -115,6 +144,7 @@ flowchart LR
|
|
|
115
144
|
style Source fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
116
145
|
|
|
117
146
|
style Ingest fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
147
|
+
style Extract fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
118
148
|
style Build fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
119
149
|
style Query fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
120
150
|
style Model fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
@@ -124,6 +154,8 @@ flowchart LR
|
|
|
124
154
|
style Main fill:#ffffff,stroke:#ffffff,color:#111111
|
|
125
155
|
style LegendArtifact fill:#f3e5f5,stroke:#8e24aa,color:#111111
|
|
126
156
|
style LegendStep fill:#eceff1,stroke:#90a4ae,color:#111111
|
|
157
|
+
style LegendStable fill:#ffffff,stroke:#8e24aa,stroke-width:2px,color:#111111
|
|
158
|
+
style LegendPluggable fill:#ffffff,stroke:#1e88e5,stroke-dasharray:6 3,stroke-width:2px,color:#111111
|
|
127
159
|
```
|
|
128
160
|
|
|
129
161
|
## Practical value
|
|
@@ -136,6 +168,7 @@ flowchart LR
|
|
|
136
168
|
|
|
137
169
|
- Initialize a corpus folder.
|
|
138
170
|
- Ingest items from file paths, web addresses, or text input.
|
|
171
|
+
- Run extraction when you want derived text artifacts from non-text sources.
|
|
139
172
|
- Reindex to refresh the catalog after edits.
|
|
140
173
|
- Build a retrieval run with a backend.
|
|
141
174
|
- Query the run to collect evidence and evaluate it with datasets.
|
|
@@ -154,13 +187,25 @@ After the first release, you can install it from Python Package Index.
|
|
|
154
187
|
python3 -m pip install biblicus
|
|
155
188
|
```
|
|
156
189
|
|
|
190
|
+
### Optional extras
|
|
191
|
+
|
|
192
|
+
Some extractors are optional so the base install stays small.
|
|
193
|
+
|
|
194
|
+
- Optical character recognition for images: `python3 -m pip install "biblicus[ocr]"`
|
|
195
|
+
- Speech to text transcription: `python3 -m pip install "biblicus[openai]"` (requires an OpenAI API key in `~/.biblicus/config.yml` or `./.biblicus/config.yml`)
|
|
196
|
+
- Broad document parsing fallback: `python3 -m pip install "biblicus[unstructured]"`
|
|
197
|
+
|
|
157
198
|
## Quick start
|
|
158
199
|
|
|
159
200
|
```
|
|
201
|
+
mkdir -p notes
|
|
202
|
+
echo "A small file note" > notes/example.txt
|
|
203
|
+
|
|
160
204
|
biblicus init corpora/example
|
|
161
205
|
biblicus ingest --corpus corpora/example notes/example.txt
|
|
162
206
|
echo "A short note" | biblicus ingest --corpus corpora/example --stdin --title "First note"
|
|
163
207
|
biblicus list --corpus corpora/example
|
|
208
|
+
biblicus extract --corpus corpora/example --step pass-through-text --step metadata-text
|
|
164
209
|
biblicus build --corpus corpora/example --backend scan
|
|
165
210
|
biblicus query --corpus corpora/example --query "note"
|
|
166
211
|
```
|
|
@@ -188,13 +233,18 @@ In an assistant system, retrieval usually produces context for a model call. Thi
|
|
|
188
233
|
|
|
189
234
|
## Learn more
|
|
190
235
|
|
|
236
|
+
Full documentation is available on [ReadTheDocs](https://biblicus.readthedocs.io/).
|
|
237
|
+
|
|
191
238
|
The documents below are written to be read in order.
|
|
192
239
|
|
|
193
240
|
- [Architecture][architecture]
|
|
241
|
+
- [Roadmap][roadmap]
|
|
242
|
+
- [Feature index][feature-index]
|
|
194
243
|
- [Corpus][corpus]
|
|
195
244
|
- [Text extraction][text-extraction]
|
|
245
|
+
- [User configuration][user-configuration]
|
|
196
246
|
- [Backends][backends]
|
|
197
|
-
- [
|
|
247
|
+
- [Demos][demos]
|
|
198
248
|
- [Testing][testing]
|
|
199
249
|
|
|
200
250
|
## Metadata and catalog
|
|
@@ -252,10 +302,18 @@ Publishing uses a Python Package Index token stored in the GitHub secret named P
|
|
|
252
302
|
|
|
253
303
|
## Documentation
|
|
254
304
|
|
|
255
|
-
Reference documentation is generated from Sphinx style docstrings.
|
|
305
|
+
Reference documentation is generated from Sphinx style docstrings.
|
|
306
|
+
|
|
307
|
+
Install development dependencies:
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
python3 -m pip install -e ".[dev]"
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Build the documentation:
|
|
256
314
|
|
|
257
315
|
```
|
|
258
|
-
|
|
316
|
+
python3 -m sphinx -b html docs docs/_build
|
|
259
317
|
```
|
|
260
318
|
|
|
261
319
|
## License
|
|
@@ -264,11 +322,15 @@ License terms are in `LICENSE`.
|
|
|
264
322
|
|
|
265
323
|
[retrieval augmented generation overview]: https://en.wikipedia.org/wiki/Retrieval-augmented_generation
|
|
266
324
|
[architecture]: docs/ARCHITECTURE.md
|
|
325
|
+
[roadmap]: docs/ROADMAP.md
|
|
326
|
+
[feature-index]: docs/FEATURE_INDEX.md
|
|
267
327
|
[corpus]: docs/CORPUS.md
|
|
268
328
|
[text-extraction]: docs/EXTRACTION.md
|
|
329
|
+
[user-configuration]: docs/USER_CONFIGURATION.md
|
|
269
330
|
[backends]: docs/BACKENDS.md
|
|
270
|
-
[
|
|
331
|
+
[demos]: docs/DEMOS.md
|
|
271
332
|
[testing]: docs/TESTING.md
|
|
272
333
|
|
|
273
334
|
[continuous-integration-badge]: https://github.com/AnthusAI/Biblicus/actions/workflows/ci.yml/badge.svg?branch=main
|
|
274
335
|
[coverage-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AnthusAI/Biblicus/main/coverage_badge.json
|
|
336
|
+
[documentation-badge]: https://readthedocs.org/projects/biblicus/badge/?version=latest
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
biblicus/__init__.py,sha256=1vPJokNgr7JcDO9eJ2SRR8VLkFG44ZaSACSaalogvYQ,432
|
|
2
|
+
biblicus/__main__.py,sha256=ipfkUoTlocVnrQDM69C7TeBqQxmHVeiWMRaT3G9rtnk,117
|
|
3
|
+
biblicus/cli.py,sha256=k09mMToSawDC7TbetwtK0RItTLO84EOJCZQKDRA-b9Y,19229
|
|
4
|
+
biblicus/constants.py,sha256=R6fZDoLVMCwgKvTaxEx7G0CstwHGaUTlW9MsmNLDZ44,269
|
|
5
|
+
biblicus/corpus.py,sha256=oBg5nbDoDBkkXaW180ixtvU9Yh0y9nOiZDEMKomtrVU,47688
|
|
6
|
+
biblicus/errors.py,sha256=uMajd5DvgnJ_-jq5sbeom1GV8DPUc-kojBaECFi6CsY,467
|
|
7
|
+
biblicus/evaluation.py,sha256=5xWpb-8f49Osh9aHzo1ab3AXOmls3Imc5rdnEC0pN-8,8143
|
|
8
|
+
biblicus/extraction.py,sha256=MYaHkhj0NWBKNcaohnLvNiHLwyps9JyZGaTxX5gHR-A,19281
|
|
9
|
+
biblicus/frontmatter.py,sha256=JOGjIDzbbOkebQw2RzA-3WDVMAMtJta2INjS4e7-LMg,2463
|
|
10
|
+
biblicus/hook_logging.py,sha256=IMvde-JhVWrx9tNz3eDJ1CY_rr5Sj7DZ2YNomYCZbz0,5366
|
|
11
|
+
biblicus/hook_manager.py,sha256=ZCAkE5wLvn4lnQz8jho_o0HGEC9KdQd9qitkAEUQRcw,6997
|
|
12
|
+
biblicus/hooks.py,sha256=OHQOmOi7rUcQqYWVeod4oPe8nVLepD7F_SlN7O_-BsE,7863
|
|
13
|
+
biblicus/ignore.py,sha256=fyjt34E6tWNNrm1FseOhgH2MgryyVBQVzxhKL5s4aio,1800
|
|
14
|
+
biblicus/models.py,sha256=fdpPRtWmtirjEKpOPL_6ZVRY0vpA2WRqMwNrOqPaauM,14204
|
|
15
|
+
biblicus/retrieval.py,sha256=A1SI4WK5cX-WbtN6FJ0QQxqlEOtQhddLrL0LZIuoTC4,4180
|
|
16
|
+
biblicus/sources.py,sha256=EFy8-rQNLsyzz-98mH-z8gEHMYbqigcNFKLaR92KfDE,7241
|
|
17
|
+
biblicus/time.py,sha256=NEHkJLJ3RH1PdJVAWMYbNCBnCb6UW9DVBLo7Qh1zO88,485
|
|
18
|
+
biblicus/uris.py,sha256=xXD77lqsT9NxbyzI1spX9Y5a3-U6sLYMnpeSAV7g-nM,2013
|
|
19
|
+
biblicus/user_config.py,sha256=DqO08yLn82DhTiFpmIyyLj_J0nMbrtE8xieTj2Cgd6A,4287
|
|
20
|
+
biblicus/_vendor/dotyaml/__init__.py,sha256=e4zbejeJRwlD4I0q3YvotMypO19lXqmT8iyU1q6SvhY,376
|
|
21
|
+
biblicus/_vendor/dotyaml/interpolation.py,sha256=PfUAEEOTFobv7Ox0E6nAxht6BqhHIDe4hP32fZn5TOs,1992
|
|
22
|
+
biblicus/_vendor/dotyaml/loader.py,sha256=KePkjyhKZSvQZphmlmlzTYZJBQsqL5qhtGV1y7G6wzM,5624
|
|
23
|
+
biblicus/_vendor/dotyaml/transformer.py,sha256=2AKPS8DMOPuYtzmM-dlwIqVbARfbBH5jYV1m5qpR49E,3725
|
|
24
|
+
biblicus/backends/__init__.py,sha256=wLXIumV51l6ZIKzjoKKeU7AgIxGOryG7T7ls3a_Fv98,1212
|
|
25
|
+
biblicus/backends/base.py,sha256=Erfj9dXg0nkRKnEcNjHR9_0Ddb2B1NvbmRksVm_g1dU,1776
|
|
26
|
+
biblicus/backends/scan.py,sha256=hdNnQWqi5IH6j95w30BZHxLJ0W9PTaOkqfWJuxCCEMI,12478
|
|
27
|
+
biblicus/backends/sqlite_full_text_search.py,sha256=KgmwOiKvkA0pv7vD0V7bcOdDx_nZIOfuIN6Z4Ij7I68,16516
|
|
28
|
+
biblicus/extractors/__init__.py,sha256=X3pu18QL85IBpYf56l6_5PUxFPhEN5qLTlOrxYpfGck,1776
|
|
29
|
+
biblicus/extractors/base.py,sha256=ka-nz_1zHPr4TS9sU4JfOoY-PJh7lbHPBOEBrbQFGSc,2171
|
|
30
|
+
biblicus/extractors/metadata_text.py,sha256=7FbEPp0K1mXc7FH1_c0KhPhPexF9U6eLd3TVY1vTp1s,3537
|
|
31
|
+
biblicus/extractors/openai_stt.py,sha256=fggErIu6YN6tXbleNTuROhfYi7zDgMd2vD_ecXZ7eXs,7162
|
|
32
|
+
biblicus/extractors/pass_through_text.py,sha256=DNxkCwpH2bbXjPGPEQwsx8kfqXi6rIxXNY_n3TU2-WI,2777
|
|
33
|
+
biblicus/extractors/pdf_text.py,sha256=YtUphgLVxyWJXew6ZsJ8wBRh67Y5ri4ZTRlMmq3g1Bk,3255
|
|
34
|
+
biblicus/extractors/pipeline.py,sha256=LY6eM3ypw50MDB2cPEQqZrjxkhVvIc6sv4UEhHdNDrE,3208
|
|
35
|
+
biblicus/extractors/rapidocr_text.py,sha256=OMAuZealLSSTFVVmBalT-AFJy2pEpHyyvpuWxlnY-GU,4531
|
|
36
|
+
biblicus/extractors/select_longest_text.py,sha256=wRveXAfYLdj7CpGuo4RoD7zE6SIfylRCbv40z2azO0k,3702
|
|
37
|
+
biblicus/extractors/select_text.py,sha256=w0ATmDy3tWWbOObzW87jGZuHbgXllUhotX5XyySLs-o,3395
|
|
38
|
+
biblicus/extractors/unstructured_text.py,sha256=l2S_wD_htu7ZHoJQNQtP-kGlEgOeKV_w2IzAC93lePE,3564
|
|
39
|
+
biblicus-0.3.0.dist-info/licenses/LICENSE,sha256=lw44GXFG_Q0fS8m5VoEvv_xtdBXK26pBcbSPUCXee_Q,1078
|
|
40
|
+
biblicus-0.3.0.dist-info/METADATA,sha256=MHE8tAh9jGiMwk5X9jPSnhRFB6uAZa3T8jo_c1zrIZM,13202
|
|
41
|
+
biblicus-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
42
|
+
biblicus-0.3.0.dist-info/entry_points.txt,sha256=BZmO4H8Uz00fyi1RAFryOCGfZgX7eHWkY2NE-G54U5A,47
|
|
43
|
+
biblicus-0.3.0.dist-info/top_level.txt,sha256=sUD_XVZwDxZ29-FBv1MknTGh4mgDXznGuP28KJY_WKc,9
|
|
44
|
+
biblicus-0.3.0.dist-info/RECORD,,
|
biblicus/extractors/cascade.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Cascade extractor plugin that composes multiple extractors.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from typing import Any, Dict, List, Optional
|
|
8
|
-
|
|
9
|
-
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
10
|
-
|
|
11
|
-
from ..corpus import Corpus
|
|
12
|
-
from ..models import CatalogItem, ExtractedText
|
|
13
|
-
from .base import TextExtractor
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CascadeStepSpec(BaseModel):
|
|
17
|
-
"""
|
|
18
|
-
Single extractor step within a cascade pipeline.
|
|
19
|
-
|
|
20
|
-
:ivar extractor_id: Extractor plugin identifier.
|
|
21
|
-
:vartype extractor_id: str
|
|
22
|
-
:ivar config: Extractor configuration mapping.
|
|
23
|
-
:vartype config: dict[str, Any]
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
model_config = ConfigDict(extra="forbid")
|
|
27
|
-
|
|
28
|
-
extractor_id: str = Field(min_length=1)
|
|
29
|
-
config: Dict[str, Any] = Field(default_factory=dict)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class CascadeExtractorConfig(BaseModel):
|
|
33
|
-
"""
|
|
34
|
-
Configuration for the cascade extractor.
|
|
35
|
-
|
|
36
|
-
:ivar steps: Ordered list of extractor steps to try.
|
|
37
|
-
:vartype steps: list[CascadeStepSpec]
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
model_config = ConfigDict(extra="forbid")
|
|
41
|
-
|
|
42
|
-
steps: List[CascadeStepSpec] = Field(min_length=1)
|
|
43
|
-
|
|
44
|
-
@model_validator(mode="after")
|
|
45
|
-
def _forbid_self_reference(self) -> "CascadeExtractorConfig":
|
|
46
|
-
if any(step.extractor_id == "cascade" for step in self.steps):
|
|
47
|
-
raise ValueError("Cascade extractor cannot include itself as a step")
|
|
48
|
-
return self
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class CascadeExtractor(TextExtractor):
|
|
52
|
-
"""
|
|
53
|
-
Extractor that tries a sequence of extractors and uses the first usable text result.
|
|
54
|
-
|
|
55
|
-
A result is considered usable when its text is non-empty after stripping whitespace.
|
|
56
|
-
|
|
57
|
-
:ivar extractor_id: Extractor identifier.
|
|
58
|
-
:vartype extractor_id: str
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
extractor_id = "cascade"
|
|
62
|
-
|
|
63
|
-
def validate_config(self, config: Dict[str, Any]) -> BaseModel:
|
|
64
|
-
"""
|
|
65
|
-
Validate cascade extractor configuration.
|
|
66
|
-
|
|
67
|
-
:param config: Configuration mapping.
|
|
68
|
-
:type config: dict[str, Any]
|
|
69
|
-
:return: Parsed config.
|
|
70
|
-
:rtype: CascadeExtractorConfig
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
return CascadeExtractorConfig.model_validate(config)
|
|
74
|
-
|
|
75
|
-
def extract_text(self, *, corpus: Corpus, item: CatalogItem, config: BaseModel) -> Optional[ExtractedText]:
|
|
76
|
-
"""
|
|
77
|
-
Run each configured extractor step until usable text is produced.
|
|
78
|
-
|
|
79
|
-
:param corpus: Corpus containing the item bytes.
|
|
80
|
-
:type corpus: Corpus
|
|
81
|
-
:param item: Catalog item being processed.
|
|
82
|
-
:type item: CatalogItem
|
|
83
|
-
:param config: Parsed configuration model.
|
|
84
|
-
:type config: CascadeExtractorConfig
|
|
85
|
-
:return: Extracted text payload or None.
|
|
86
|
-
:rtype: ExtractedText or None
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
cascade_config = config if isinstance(config, CascadeExtractorConfig) else CascadeExtractorConfig.model_validate(config)
|
|
90
|
-
for step in cascade_config.steps:
|
|
91
|
-
from . import get_extractor
|
|
92
|
-
|
|
93
|
-
extractor = get_extractor(step.extractor_id)
|
|
94
|
-
parsed_step_config = extractor.validate_config(step.config)
|
|
95
|
-
result = extractor.extract_text(corpus=corpus, item=item, config=parsed_step_config)
|
|
96
|
-
if result is None:
|
|
97
|
-
continue
|
|
98
|
-
if not result.text.strip():
|
|
99
|
-
continue
|
|
100
|
-
return result
|
|
101
|
-
return None
|
biblicus-0.2.0.dist-info/RECORD
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
biblicus/__init__.py,sha256=3IXdbt-q80_BlKDwTsZw7MScRW4hBgQ-Vn6xHbgNwE8,432
|
|
2
|
-
biblicus/__main__.py,sha256=ipfkUoTlocVnrQDM69C7TeBqQxmHVeiWMRaT3G9rtnk,117
|
|
3
|
-
biblicus/cli.py,sha256=zDD6juQGTDmrRE2DHUku-G3wV3AtXjwYTNDFACwpdC0,19501
|
|
4
|
-
biblicus/constants.py,sha256=R6fZDoLVMCwgKvTaxEx7G0CstwHGaUTlW9MsmNLDZ44,269
|
|
5
|
-
biblicus/corpus.py,sha256=5naoFi0GSKBg4RFd6wOU-U30NMbG6bfs_RM90JcvDGA,47460
|
|
6
|
-
biblicus/evaluation.py,sha256=H_W35vF5_L4B2JCfLu19VRu402tZ2pFkN2BbBP69lVY,8119
|
|
7
|
-
biblicus/extraction.py,sha256=WX1LRsKrsyHI4Wido6gMwukzRGf5cfPWvRASgu_MRN4,10614
|
|
8
|
-
biblicus/frontmatter.py,sha256=8Tqlpd3bVzZrGRB9Rdj2IwHMSJLvd2ABxMNOi3L5br4,2466
|
|
9
|
-
biblicus/hook_logging.py,sha256=8Rl3BpkfTexSJ7rFi94kl6DMRDD-8eu2N7zv18wXyUM,5371
|
|
10
|
-
biblicus/hook_manager.py,sha256=ucDZoVM-9fg1gQAhUxi-PECaNlHoegAxb-kYCx-OMZs,6987
|
|
11
|
-
biblicus/hooks.py,sha256=OfG3VsCDWQVVZnOTQHnN9GQ0AIws9SK6-85WYTrKkzk,7847
|
|
12
|
-
biblicus/ignore.py,sha256=Di37CTlg6Mg3SKJc2qxZcZdYX00IcTORB2hb0g-Jins,1803
|
|
13
|
-
biblicus/models.py,sha256=6cgJX7Jmm5rBVrXWH46fQf3v__jSyDy73MnKaUQMSHQ,11099
|
|
14
|
-
biblicus/retrieval.py,sha256=T7HELWCNAxZ26yj7dPH8IBUaxV_gx8Ql9iwwGz0teyI,4184
|
|
15
|
-
biblicus/sources.py,sha256=C4P8oM6d50tLXr4z9Shsv4z-hDiQuylXfkT3Bx03dEM,5844
|
|
16
|
-
biblicus/time.py,sha256=rvp2fJXSLVmyA76GCfNKtZoifASodemJTOWN8smPt0s,486
|
|
17
|
-
biblicus/uris.py,sha256=sRDyGmoHr_H4XR4qv_lSbQJXylYD0fNEr02H5wjomnQ,1986
|
|
18
|
-
biblicus/backends/__init__.py,sha256=5OXKSzsn7THhwh9T5StOvEqojx_85XXuYSGdTpMK11U,1214
|
|
19
|
-
biblicus/backends/base.py,sha256=699TKygGgL72Ifkhz1V890nOK6BslwO0-OY7xeqZl-I,1764
|
|
20
|
-
biblicus/backends/scan.py,sha256=DZ-CgZ0jy6_928hu4dASJ8_JH7BTfF8gwVkVhd38W1U,12421
|
|
21
|
-
biblicus/backends/sqlite_full_text_search.py,sha256=FMpASLeK5diK-Uyhr4pqtpDpb_Qyk5_XRaXAKUHDzjs,16502
|
|
22
|
-
biblicus/extractors/__init__.py,sha256=_6Z_JkLoDYwmay76y1fy11lCSqDDizMDPX3Vke_l8x4,1008
|
|
23
|
-
biblicus/extractors/base.py,sha256=yvp709uUCnPEbK-bx6u5WKNPPH3SBWhbSaewoyUIgvA,1870
|
|
24
|
-
biblicus/extractors/cascade.py,sha256=ExojAYsARtF99zVg78wY_wifVfDaJFa6wiRIaT-cpRo,3209
|
|
25
|
-
biblicus/extractors/metadata_text.py,sha256=C0i8fcEC9aLmwhSdK9IlZVZ9ugOocIe0y522pSjvaCA,3203
|
|
26
|
-
biblicus/extractors/pass_through_text.py,sha256=ngDyI13RpCldP-OzV4q9lBTGPxDL6MDxp7OCo1rORyQ,2421
|
|
27
|
-
biblicus-0.2.0.dist-info/licenses/LICENSE,sha256=lw44GXFG_Q0fS8m5VoEvv_xtdBXK26pBcbSPUCXee_Q,1078
|
|
28
|
-
biblicus-0.2.0.dist-info/METADATA,sha256=nTB344GRVrKuT6oPOrWBpFA_BiG3UAIgq3wCoHEVDgw,10307
|
|
29
|
-
biblicus-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
30
|
-
biblicus-0.2.0.dist-info/entry_points.txt,sha256=BZmO4H8Uz00fyi1RAFryOCGfZgX7eHWkY2NE-G54U5A,47
|
|
31
|
-
biblicus-0.2.0.dist-info/top_level.txt,sha256=sUD_XVZwDxZ29-FBv1MknTGh4mgDXznGuP28KJY_WKc,9
|
|
32
|
-
biblicus-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|