Documentation for ToMeDa
tomeda.t11_create_dataverse_tsv_from_mapping
This file gets a metadata schema as json from the dataset a dataset tsv and mapping table will be derived from it outputs a dataverse tsv file and a mapping table
Input
json schema file (no data content, just structure)
Output
2 files:
1. dataverse tsv file with all keys that are not in citation.tsv
2. mapping table for all keys that are not in citation.tsv with depth 2
at most (schema<->dataverse)
logger
module-attribute
logger: TraceLogger = getLogger(__name__)
types
module-attribute
types = []
InfoElement
dataclass
InfoElement(
name: str,
title: str,
description: str,
allow_multiples: bool,
required: bool,
type: str,
dataverse_name: str,
displayFormat: str | None = None,
controlledVocabulary: list[str] | None = None,
)
allow_multiples
instance-attribute
allow_multiples: bool
controlledVocabulary
class-attribute
instance-attribute
controlledVocabulary: list[str] | None = None
dataverse_name
instance-attribute
dataverse_name: str
description
instance-attribute
description: str
displayFormat
class-attribute
instance-attribute
displayFormat: str | None = None
name
instance-attribute
name: str
required
instance-attribute
required: bool
title
instance-attribute
title: str
type
instance-attribute
type: str
NotLeafError
NotLeafError(message='Not a leaf Error')
Bases: Exception
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
157 158 |
|
assemble_dataset_field_line
assemble_dataset_field_line(
line_information: InfoElement, display_order: int
) -> DatasetFieldLine
Create a DatasetFieldLine instance using provided line information and order.
Done for https://guides.dataverse.org/en/latest/admin/metadatacustomization.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line_information |
dict
|
Dictionary containing information about a line. |
required |
display_order |
int
|
Integer representing the order of display. |
required |
Returns:
Type | Description |
---|---|
DatasetFieldLine
|
DatasetFieldLine instance. |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|
create_InfoElement_structure
create_InfoElement_structure(
entry_description_raw: dict[str, dict[str, str]]
) -> dict[str, InfoElement]
Create a dictionary with InfoElement instances.
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
generate_controlled_vocabulary_block
generate_controlled_vocabulary_block(
entry_description: dict[str, InfoElement]
) -> ControlledVocabulary
Generate a controlled vocabulary block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_description |
dict
|
Description of the entries. |
required |
Returns:
Type | Description |
---|---|
ControlledVocabulary
|
ControlledVocabulary instance. |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|
generate_dataset_field_block
generate_dataset_field_block(
auto_mapping: dict | list,
entry_description: dict[str, InfoElement],
) -> DatasetField
Generate a dataset field block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_mapping |
dict or list
|
Auto-generated mapping. |
required |
entry_description |
dict[str, InfoElement]
|
Description of the entries. |
required |
Returns:
Type | Description |
---|---|
DatasetField
|
DatasetField instance. |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|
generate_metadata_block
generate_metadata_block(schema_name: str) -> MetadataBlock
Generate a metadata block with the provided schema name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_name |
str
|
Name of the schema. |
required |
Returns:
Type | Description |
---|---|
MetadataBlock
|
MetadataBlock instance. |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
generate_tsv
generate_tsv(
auto_mapping: list,
entry_description: dict[str, InfoElement],
schema_name,
) -> dict
Generate a TSV format dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_mapping |
list
|
Auto-generated mapping. |
required |
entry_description |
dict[str, InfoElement]
|
Description of the entries. |
required |
schema_name |
str
|
Name of the schema. |
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary in TSV format. |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|
main
main(param: TomedaParameter) -> None
Main function of the script. This function triggers the whole process of creating a mapping table and dataverse TSV file. It gets the paths of required files from the command-line arguments, generates a mapping table and finally creates a TSV file which can be uploaded to dataverse.
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|
write_tsv
write_tsv(
tsv_dict: dict, output_path: Path, overwrite: bool
) -> None
Write the TSV data into a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tsv_dict |
dict
|
A dictionary containing the TSV data. |
required |
output_path |
Path
|
File path to the output file. |
required |
overwrite |
bool
|
If True, the output file will be overwritten if it already exists. |
required |
Source code in tomeda/t11_create_dataverse_tsv_from_mapping.py
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 |
|