utils¤
Module Description¤
Utility functions and classes for the Lexos corpus module.
LexosModelCache
¤
A simple cache for spaCy models.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the cache. |
get_model |
Get a model from the cache or load it if not cached. |
Source code in lexos/corpus/utils.py
__init__()
¤
get_model(model_name: str) -> Language
¤
Get a model from the cache or load it if not cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The spaCy model name to load (e.g., 'en_core_web_sm'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Language |
Language
|
The loaded spaCy language model. |
Source code in lexos/corpus/utils.py
rendering:
show_root_heading: true
heading_level: 3
__init__()
¤
rendering:
show_root_heading: true
heading_level: 3
get_model(model_name: str) -> Language
¤
Get a model from the cache or load it if not cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The spaCy model name to load (e.g., 'en_core_web_sm'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Language |
Language
|
The loaded spaCy language model. |
Source code in lexos/corpus/utils.py
rendering:
show_root_heading: true
heading_level: 3
RecordsDict
¤
Bases: dict
A dictionary-like class for storing Record objects.
This class ensures that no ids can be overwritten, and it raises an error if an attempt is made to do so.
Methods:
| Name | Description |
|---|---|
__setitem__ |
Set an item in the Records dictionary. |
update |
Update the Records dictionary with a non-prexisting mapping or keyword arguments. |
Source code in lexos/corpus/utils.py
__setitem__(key, value)
¤
Set an item in the Records dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The ID of the Record. |
required |
value
|
Record
|
The Record object to set. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the key already exists in the Records dictionary. |
Source code in lexos/corpus/utils.py
update(other=None, **kwargs: Any) -> None
¤
Update the Records dictionary with a non-prexisting mapping or keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Mapping or iterable
|
An optional mapping or iterable of key-value pairs to update the Records dictionary. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to update the Records dictionary. |
{}
|
Source code in lexos/corpus/utils.py
rendering:
show_root_heading: true
heading_level: 3
__setitem__(key, value)
¤
Set an item in the Records dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The ID of the Record. |
required |
value
|
Record
|
The Record object to set. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the key already exists in the Records dictionary. |
Source code in lexos/corpus/utils.py
rendering:
show_root_heading: true
heading_level: 3
update(other=None, **kwargs: Any) -> None
¤
Update the Records dictionary with a non-prexisting mapping or keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Mapping or iterable
|
An optional mapping or iterable of key-value pairs to update the Records dictionary. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to update the Records dictionary. |
{}
|
Source code in lexos/corpus/utils.py
rendering:
show_root_heading: true
heading_level: 3