base_loader¤
The BaseLoader Class¤
The BaseLoader class is the base class for all loaders in the IO module. Additional modules should inherit from BaseLoader.
BaseLoader
pydantic-model
¤
Bases: BaseModel, ABC
BaseLoader.
Config:
arbitrary_types_allowed:True
Fields:
-
paths(list) -
mime_types(list) -
names(list) -
texts(list) -
errors(list)
Source code in lexos/io/base_loader.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
data: dict[str, list]
property
¤
Get the data as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
dict[str, list]: A dictionary containing the paths, mime_types, names, texts, and errors. |
df: pd.DataFrame
property
¤
Get a pandas DataFrame of file records.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: A DataFrame containing file metadata and content. |
errors: list = []
pydantic-field
¤
The list of loading errors.
mime_types: list = []
pydantic-field
¤
The list of text mime types.
names: list = []
pydantic-field
¤
The list of text names.
paths: list = []
pydantic-field
¤
The list of paths.
records: list[dict[str, str]]
property
¤
Get a list of file records.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict]: List of dictionaries containing file metadata and content. |
list[dict[str, str]]
|
Each dict has keys: path, mime_type, name, text |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of paths, mime_types, names and texts don't match. |
Note
Validates that all lists have the same length before returning the records.
texts: list = []
pydantic-field
¤
The list of loaded texts.
__iter__() -> Generator[dict, None, None]
¤
dedupe(subset: Optional[list[str]] = None) -> pd.DataFrame
¤
Deduplicate a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
Optional[list[str]]
|
The columns to consider for deduplication. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The deduplicated DataFrame. |
Source code in lexos/io/base_loader.py
load_dataset(dataset) -> None
abstractmethod
¤
Load a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataLoader
|
The dataset to load. |
required |
reset() -> None
¤
Reset the class attributes to empty lists.
show_duplicates(subset: Optional[list[str]] = None) -> pd.DataFrame | None
¤
Show duplicates in a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
Optional[list[str]] = None
|
The columns to consider for checking duplicates. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame: The DataFrame with duplicates. |
Source code in lexos/io/base_loader.py
to_csv(path: Path | str, **kwargs) -> None
¤
Save the data to a csv file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |
to_excel(path: Path | str, **kwargs) -> None
¤
Save the data to an Excel file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |
to_json(path: Path | str, **kwargs) -> None
¤
Save the data to a json file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |
__iter__() -> Generator[dict, None, None]
¤
data: dict[str, list]
property
¤
Get the data as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
dict[str, list]: A dictionary containing the paths, mime_types, names, texts, and errors. |
df: pd.DataFrame
property
¤
Get a pandas DataFrame of file records.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: A DataFrame containing file metadata and content. |
records: list[dict[str, str]]
property
¤
Get a list of file records.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
list[dict]: List of dictionaries containing file metadata and content. |
list[dict[str, str]]
|
Each dict has keys: path, mime_type, name, text |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of paths, mime_types, names and texts don't match. |
Note
Validates that all lists have the same length before returning the records.
load_dataset(dataset) -> None
abstractmethod
¤
Load a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataLoader
|
The dataset to load. |
required |
dedupe(subset: Optional[list[str]] = None) -> pd.DataFrame
¤
Deduplicate a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
Optional[list[str]]
|
The columns to consider for deduplication. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The deduplicated DataFrame. |
Source code in lexos/io/base_loader.py
reset() -> None
¤
Reset the class attributes to empty lists.
show_duplicates(subset: Optional[list[str]] = None) -> pd.DataFrame | None
¤
Show duplicates in a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
Optional[list[str]] = None
|
The columns to consider for checking duplicates. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
pd.DataFrame: The DataFrame with duplicates. |
Source code in lexos/io/base_loader.py
to_csv(path: Path | str, **kwargs) -> None
¤
Save the data to a csv file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |
to_excel(path: Path | str, **kwargs) -> None
¤
Save the data to an Excel file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |
to_json(path: Path | str, **kwargs) -> None
¤
Save the data to a json file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The path to save the csv file. |
required |