integration¤
Module Description¤
Database integration layer for the Lexos Corpus class.
This module extends the existing Corpus class with optional SQLite database capabilities while maintaining full compatibility with the file-based system.
SQLiteCorpus
pydantic-model
¤
Bases: Corpus
Corpus with SQLite database backend support.
Extends the standard Corpus with optional database storage: - Dual storage: files + database - Full-text search across records - Efficient metadata queries - Optional database-only mode
The database integration is completely optional and does not break existing file-based workflows.
Fields:
-
corpus_dir(str) -
corpus_metadata_file(str) -
name(str) -
records(RecordsDict) -
names(dict[str, list[str]]) -
meta(dict[str, Any]) -
analysis_results(dict[str, dict[str, Any]]) -
model_cache(LexosModelCache) -
num_active_docs(int) -
num_docs(int) -
num_terms(int) -
num_tokens(int) -
terms(set) -
use_sqlite(bool) -
sqlite_only(bool) -
sqlite_path(Optional[str]) -
db(Optional[SQLiteBackend])
Source code in lexos/corpus/sqlite/integration.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
active_terms: set
property
¤
Return the set of active terms in the Corpus.
Returns:
| Name | Type | Description |
|---|---|---|
set |
set
|
A set of active term strings found in active parsed records. |
analysis_results: dict[str, dict[str, Any]]
pydantic-field
¤
Storage for results from external analysis modules (kmeans, topwords, kwic, etc.)
corpus_dir: str = 'corpus'
pydantic-field
¤
The path to the directory where the corpus is stored.
corpus_metadata_file: str = 'corpus_metadata.json'
pydantic-field
¤
The name of the corpus metadata file.
db: Optional[SQLiteBackend] = None
pydantic-field
¤
Database connection object
meta: dict[str, Any] = {}
pydantic-field
¤
Metadata dictionary for arbitrary metadata relating to the corpus.
meta_df: pd.DataFrame
property
¤
Return a DataFrame of the Corpus metadata.
model_cache: LexosModelCache = LexosModelCache()
pydantic-field
¤
A cache for spaCy models used in the Corpus.
name: str = None
pydantic-field
¤
The name of the corpus.
num_active_docs: int = 0
pydantic-field
¤
Number of active records in the corpus.
num_active_terms: int
property
¤
Return the number of active terms in the Corpus.
num_active_tokens: int
property
¤
Return the number of active tokens in the Corpus.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of tokens in active parsed records. |
num_docs: int = 0
pydantic-field
¤
Total number of records in the corpus.
num_terms: int = 0
pydantic-field
¤
Total number of unique terms in the corpus.
num_tokens: int = 0
pydantic-field
¤
Total number of tokens in the corpus.
records: RecordsDict = {}
pydantic-field
¤
Dictionary of records in the corpus.
sqlite_only: bool = False
pydantic-field
¤
Whether to use database-only mode
sqlite_path: Optional[str] = None
pydantic-field
¤
Path to SQLite database file
terms: set = set()
pydantic-field
¤
Set of unique terms in the corpus.
use_sqlite: bool = False
pydantic-field
¤
Whether to enable database storage
__del__()
¤
__init__(**data: Any)
¤
Initialize corpus with optional database integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**data
|
Any
|
Standard Corpus initialization parameters |
{}
|
Source code in lexos/corpus/sqlite/integration.py
__iter__() -> Iterable[Record]
¤
Make the corpus iterable.
Returns:
| Type | Description |
|---|---|
Iterable[Record]
|
Iterator[Record]: An iterator over the Record objects in the corpus. |
__repr__()
¤
Return a string representation of the Corpus.
Source code in lexos/corpus/corpus.py
add(content, name: Optional[str] = None, is_active: Optional[bool] = True, model: Optional[str] = None, extensions: Optional[list[str]] = None, metadata: Optional[dict[str, Any]] = None, id_type: Optional[str] = 'uuid4', cache: Optional[bool] = False, store_in_db: Optional[bool] = None)
¤
Add a record to the corpus with optional database storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | Doc | Record
|
The content of the record |
required |
name
|
Optional[str]
|
Optional name for the record |
None
|
is_active
|
Optional[bool]
|
Whether the record is active |
True
|
model
|
Optional[str]
|
spaCy model name for parsing |
None
|
extensions
|
Optional[list[str]]
|
List of spaCy extensions to add |
None
|
metadata
|
Optional[dict[str, Any]]
|
Optional metadata dictionary |
None
|
id_type
|
Optional[str]
|
Type of ID to generate ('uuid4' or 'int') |
'uuid4'
|
cache
|
Optional[bool]
|
Whether to cache the record in memory |
False
|
store_in_db
|
Optional[bool]
|
Whether to store the record in the database |
None
|
Source code in lexos/corpus/sqlite/integration.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
add_from_files(paths: Path | str | list[Path | str], max_workers: Optional[int] = None, worker_strategy: str = 'auto', batch_size: int = 100, show_progress: bool = True, name_template: Optional[str] = None, is_active: bool = True, model: Optional[str] = None, extensions: Optional[list[str]] = None, metadata: Optional[dict[str, Any]] = None, id_type: str = 'uuid4') -> None
¤
Load files directly into corpus using parallel I/O.
This method streams files into the corpus without holding all content in memory, making it suitable for very large datasets. Files are loaded in parallel using the ParallelLoader with all its optimization features (smart file ordering, auto-tuning, etc.).
State updates are deferred until all files are loaded for optimal performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Path | str | list[Path | str]
|
File paths or directories to load. |
required |
max_workers
|
Optional[int]
|
Maximum number of worker threads. If None, auto-calculated based on worker_strategy. |
None
|
worker_strategy
|
str
|
Worker allocation strategy. Options: - "auto": Analyzes file types and chooses optimal strategy (default) - "io_bound": More workers for I/O-intensive operations - "cpu_bound": Fewer workers for CPU-intensive operations - "balanced": Middle ground between I/O and CPU |
'auto'
|
batch_size
|
int
|
Number of files to process in each batch. Default 100. |
100
|
show_progress
|
bool
|
Whether to show progress bar. Default True. |
True
|
name_template
|
Optional[str]
|
Template for generating record names. Can include {filename}, {stem}, {index}. If None, uses filename stem. |
None
|
is_active
|
bool
|
Whether records should be marked as active. Default True. |
True
|
model
|
Optional[str]
|
Name of language model used to parse records. |
None
|
extensions
|
Optional[list[str]]
|
List of extension names to add to records. |
None
|
metadata
|
Optional[dict[str, Any]]
|
Metadata to add to all records. |
None
|
id_type
|
str
|
Type of ID to generate ("integer" or "uuid4"). Default "uuid4". |
'uuid4'
|
Example
Source code in lexos/corpus/corpus.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
close()
¤
export_statistical_fingerprint() -> dict[str, Any]
¤
Export standardized statistical summary for external modules.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing corpus statistical fingerprint for external module consumption |
Note
This provides the standardized API for external modules to consume corpus statistics.
Source code in lexos/corpus/corpus.py
filter_records(is_active: Optional[bool] = None, is_parsed: Optional[bool] = None, model: Optional[str] = None, min_tokens: Optional[int] = None, max_tokens: Optional[int] = None, limit: Optional[int] = None, use_database: bool = True) -> list[Record]
¤
Filter records by various criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
Optional[bool]
|
Filter by active status |
None
|
is_parsed
|
Optional[bool]
|
Filter by parsed status |
None
|
model
|
Optional[str]
|
Filter by spaCy model name |
None
|
min_tokens
|
Optional[int]
|
Minimum number of tokens |
None
|
max_tokens
|
Optional[int]
|
Maximum number of tokens |
None
|
limit
|
Optional[int]
|
Maximum number of results |
None
|
use_database
|
bool
|
Whether to use database filtering (vs in-memory) |
True
|
Returns:
| Type | Description |
|---|---|
list[Record]
|
List of matching Record objects |
Source code in lexos/corpus/sqlite/integration.py
get(id: Optional[str | list[str]] = None, name: Optional[str | list[str]] = None) -> Record | list[Record]
¤
Get a record from the Corpus by ID.
Tries to get the record from memory; otherwise loads it from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str | list[str]
|
A record id or list of ids from the Corpus records. |
None
|
name
|
str | list[str]
|
A record name or list of names from the Corpus records. |
None
|
Returns:
| Type | Description |
|---|---|
Record | list[Record]
|
Record | list[Record]: The record(s) with the given ID(s) or name(s). |
Source code in lexos/corpus/corpus.py
get_analysis_results(module_name: str = None) -> dict[str, Any]
¤
Retrieve analysis results from external modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Specific module name to retrieve, or None for all results |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing analysis results |
Source code in lexos/corpus/corpus.py
get_stats() -> dict[str, Any]
¤
Get corpus statistics from the database.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing database-derived statistics |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
import_analysis_results(module_name: str, results_data: dict[str, Any], version: str = '1.0.0', overwrite: bool = False) -> None
¤
Import analysis results from external modules into corpus metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Name of the external module (e.g., 'kmeans', 'topwords', 'kwic', 'text_classification') |
required |
results_data
|
dict[str, Any]
|
Dictionary containing the analysis results |
required |
version
|
str
|
Version string for result versioning and compatibility |
'1.0.0'
|
overwrite
|
bool
|
Whether to overwrite existing results for this module |
False
|
Note
This is a framework implementation. Full functionality requires peer modules to be implemented and their result schemas defined.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in lexos/corpus/corpus.py
load(include_docs: bool = False, active_only: bool = True) -> int
¤
Load records from database into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_docs
|
bool
|
Whether to deserialize spaCy Doc content |
False
|
active_only
|
bool
|
Whether to load only active records |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of records loaded |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
remove(id: Optional[str | list[str]] = None, name: Optional[str | list[str]] = None) -> None
¤
Remove a record from the corpus by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str | list[str]
|
The ID of the record to remove. |
None
|
name
|
str | list[str]
|
The name of the record to remove. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in lexos/corpus/corpus.py
save(path: Path | str = None) -> None
¤
Save the Corpus as a zip archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the Corpus to. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in lexos/corpus/corpus.py
search(query: str, limit: int = 100, include_inactive: bool = False, model_filter: Optional[str] = None, load_from_db: bool = True) -> list[Record]
¤
Perform full-text search on corpus records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
FTS5 search query string |
required |
limit
|
int
|
Maximum number of results to return |
100
|
include_inactive
|
bool
|
Whether to include inactive records |
False
|
model_filter
|
Optional[str]
|
Optional filter by spaCy model name |
None
|
load_from_db
|
bool
|
Whether to load results from database (vs memory) |
True
|
Returns:
| Type | Description |
|---|---|
list[Record]
|
List of matching Record objects |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
set(id: str, **props) -> None
¤
Set a property or properties of a record in the Corpus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
A record id. |
required |
**props
|
dict
|
The dict containing any other properties to set. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in lexos/corpus/corpus.py
sync(overwrite: bool = False) -> int
¤
Synchronize existing file-based records to the database.
This method loads records from the corpus directory on disk and adds them to the database. If records are already in memory, they will be used instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overwrite
|
bool
|
Whether to overwrite existing database records |
False
|
Returns:
| Type | Description |
|---|---|
int
|
Number of records synchronized |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
term_counts(n: Optional[int] = 10, most_common: Optional[bool] = True) -> Counter
¤
Get a Counter with the most common Corpus term counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Optional[int]
|
The number of most common terms to return. Defaults to 10. |
10
|
most_common
|
Optional[bool]
|
If True, return the n most common terms; otherwise, return the n least common terms. |
True
|
Returns:
| Type | Description |
|---|---|
Counter
|
A collections.Counter object containing the n most common term counts for all records in the Corpus. |
Source code in lexos/corpus/corpus.py
to_df(exclude: list[str] = ['content', 'terms', 'tokens']) -> pd.DataFrame
¤
Return a table of the Corpus records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
list[str]
|
A list of fields to exclude from the dataframe. If you wish to exclude metadata fields with the same name as model fields, you can use the prefix "metadata_" to avoid conflicts. |
['content', 'terms', 'tokens']
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A dataframe representing the records in the Corpus. |
Source code in lexos/corpus/corpus.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
validate_analysis_compatibility(module_name: str) -> dict[str, Any]
¤
Validate if stored analysis results are compatible with current corpus state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Name of the module to validate |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing validation results and recommendations |
Source code in lexos/corpus/corpus.py
rendering:
show_root_heading: true
heading_level: 3
__init__(**data: Any)
¤
Initialize corpus with optional database integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**data
|
Any
|
Standard Corpus initialization parameters |
{}
|
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
_add_to_backend(content, name: Optional[str] = None, is_active: Optional[bool] = True, model: Optional[str] = None, extensions: Optional[list[str]] = None, metadata: Optional[dict[str, Any]] = None, id_type: Optional[str] = 'uuid4')
¤
Add records in database-only mode without file storage.
Source code in lexos/corpus/sqlite/integration.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
rendering:
show_root_heading: true
heading_level: 3
__del__()
¤
rendering:
show_root_heading: true
heading_level: 3
_get_timestamp() -> str
¤
rendering:
show_root_heading: true
heading_level: 3
_load_records_from_disk()
¤
Load records from the corpus directory into memory.
This is a helper method for sync() to load file-based records from disk before syncing them to the database.
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
_initialize_metadata()
¤
Initialize corpus metadata in the database.
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
_sanitize_metadata(metadata: dict[str, Any]) -> dict[str, Any]
¤
Convert non-JSON-serializable types to strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any]
|
Original metadata dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Sanitized metadata dictionary with JSON-serializable values |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
_update_corpus_state()
¤
Update corpus state in both memory and database.
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
add(content, name: Optional[str] = None, is_active: Optional[bool] = True, model: Optional[str] = None, extensions: Optional[list[str]] = None, metadata: Optional[dict[str, Any]] = None, id_type: Optional[str] = 'uuid4', cache: Optional[bool] = False, store_in_db: Optional[bool] = None)
¤
Add a record to the corpus with optional database storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | Doc | Record
|
The content of the record |
required |
name
|
Optional[str]
|
Optional name for the record |
None
|
is_active
|
Optional[bool]
|
Whether the record is active |
True
|
model
|
Optional[str]
|
spaCy model name for parsing |
None
|
extensions
|
Optional[list[str]]
|
List of spaCy extensions to add |
None
|
metadata
|
Optional[dict[str, Any]]
|
Optional metadata dictionary |
None
|
id_type
|
Optional[str]
|
Type of ID to generate ('uuid4' or 'int') |
'uuid4'
|
cache
|
Optional[bool]
|
Whether to cache the record in memory |
False
|
store_in_db
|
Optional[bool]
|
Whether to store the record in the database |
None
|
Source code in lexos/corpus/sqlite/integration.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
rendering:
show_root_heading: true
heading_level: 3
filter_records(is_active: Optional[bool] = None, is_parsed: Optional[bool] = None, model: Optional[str] = None, min_tokens: Optional[int] = None, max_tokens: Optional[int] = None, limit: Optional[int] = None, use_database: bool = True) -> list[Record]
¤
Filter records by various criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
Optional[bool]
|
Filter by active status |
None
|
is_parsed
|
Optional[bool]
|
Filter by parsed status |
None
|
model
|
Optional[str]
|
Filter by spaCy model name |
None
|
min_tokens
|
Optional[int]
|
Minimum number of tokens |
None
|
max_tokens
|
Optional[int]
|
Maximum number of tokens |
None
|
limit
|
Optional[int]
|
Maximum number of results |
None
|
use_database
|
bool
|
Whether to use database filtering (vs in-memory) |
True
|
Returns:
| Type | Description |
|---|---|
list[Record]
|
List of matching Record objects |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
get_stats() -> dict[str, Any]
¤
Get corpus statistics from the database.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing database-derived statistics |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
search(query: str, limit: int = 100, include_inactive: bool = False, model_filter: Optional[str] = None, load_from_db: bool = True) -> list[Record]
¤
Perform full-text search on corpus records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
FTS5 search query string |
required |
limit
|
int
|
Maximum number of results to return |
100
|
include_inactive
|
bool
|
Whether to include inactive records |
False
|
model_filter
|
Optional[str]
|
Optional filter by spaCy model name |
None
|
load_from_db
|
bool
|
Whether to load results from database (vs memory) |
True
|
Returns:
| Type | Description |
|---|---|
list[Record]
|
List of matching Record objects |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
sync(overwrite: bool = False) -> int
¤
Synchronize existing file-based records to the database.
This method loads records from the corpus directory on disk and adds them to the database. If records are already in memory, they will be used instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overwrite
|
bool
|
Whether to overwrite existing database records |
False
|
Returns:
| Type | Description |
|---|---|
int
|
Number of records synchronized |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
load(include_docs: bool = False, active_only: bool = True) -> int
¤
Load records from database into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_docs
|
bool
|
Whether to deserialize spaCy Doc content |
False
|
active_only
|
bool
|
Whether to load only active records |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of records loaded |
Raises:
| Type | Description |
|---|---|
LexosException
|
If database is not enabled |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3
close()
¤
rendering:
show_root_heading: true
heading_level: 3
create_corpus(corpus_dir: str = 'corpus', sqlite_path: Optional[Union[str, Path]] = None, name: Optional[str] = None, sqlite_only: bool = False, **kwargs: Any) -> SQLiteCorpus
¤
Convenience function to create a SQLite-enabled corpus with sensible defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_dir
|
str
|
Directory for file-based storage |
'corpus'
|
sqlite_path
|
Optional[Union[str, Path]]
|
Path to SQLite database (None for auto-generated) |
None
|
name
|
Optional[str]
|
Corpus name |
None
|
sqlite_only
|
bool
|
Whether to use database-only mode |
False
|
**kwargs
|
Any
|
Additional Corpus initialization parameters |
{}
|
Returns:
| Type | Description |
|---|---|
SQLiteCorpus
|
SQLiteCorpus instance |
Source code in lexos/corpus/sqlite/integration.py
rendering:
show_root_heading: true
heading_level: 3