lib
This module contains the main functionality to create PID records from resources and to add them to the Typed PID-Maker and Elasticsearch. It initializes the repositories and the connectors and provides functions to add entries to PID records and to create PID records from resources or from scratch.
getRepository ¶
getRepository(repo: str) -> AbstractRepository
Get the repository object for the given repository name. If the repository is not found, a ValueError is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
str
|
The name of the repository |
required |
Returns:
Name | Type | Description |
---|---|---|
AbstractRepository |
AbstractRepository
|
The repository object |
Raises:
Type | Description |
---|---|
ValueError
|
If the repository is not found |
Source code in src/nmr_FAIR_DOs/lib.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
getRepositories ¶
getRepositories(
repos: str | list[str] | None,
) -> list[AbstractRepository]
Get the repository objects for the given repository names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repos |
str | list[str] | None
|
The name of the repositories or None to get all repositories |
required |
Returns:
Type | Description |
---|---|
list[AbstractRepository]
|
list[AbstractRepository]: The repository objects |
Raises:
Type | Description |
---|---|
ValueError
|
If the input is invalid |
Source code in src/nmr_FAIR_DOs/lib.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
addRelationship ¶
addRelationship(
presumed_pid: str,
entries: list[PIDRecordEntry],
onSuccess: Callable[[str], None] | None = None,
allowRetry: bool = True,
) -> str
This method creates a relationship between two FAIR-DOs by adding entries to the PID record with the given PID. To accomplish this, the method first checks if the PID record already exists in the list of PID records to be created or in the list of PID records. If the PID record is not found, the method searches for the PID record in Elasticsearch and gets it from the Typed PID-Maker. If the PID record is still not found, the method raises an exception. The method then adds the entries to the PID record and calls the onSuccess function if it is given. Usually, this onSuccess function is used to add a relationship from the target PID record to the PID of the PID record that the entries are added to. This feature allows the creation of bidirectional relationships between two FAIR-DOs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
presumed_pid |
str
|
The PID of the target PID record. |
required |
entries |
list[PIDRecordEntry]
|
The PIDRecordEntries to add to the PID record. See PIDRecordEntry for more information. |
required |
onSuccess |
function
|
The function to call after the entries have been added to the PID record (optional). This function gets the PID of the PID record as an argument. |
None
|
allowRetry |
bool
|
If true, the function will retry to add the entries to the PID record if it fails the first time (optional). Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The PID of the PID record the entries were added to or "None" if the PID record was not found. |
Raises:
Type | Description |
---|---|
Exception
|
If any error occurs during the addition of the entries to the PID record |
Source code in src/nmr_FAIR_DOs/lib.py
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 |
|
create_pidRecords_from_resources
async
¶
create_pidRecords_from_resources(
repo: AbstractRepository, resources: list[dict]
) -> None
This function PID records for the given resources of the given repository. It extracts the PID records from the resources and adds them to the list of PID records to be created. If the repository FDO is not found, it is created and added to the list of PID records to be created. If an error occurs during the creation of the PID records, the error is added to the list of errors for further investigation by the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
AbstractRepository
|
The repository to create PID records for |
required |
resources |
list[dict]
|
A list of resources to create PID records from (e.g., JSON objects). The format of the resources is repository specific. |
required |
Returns:
Type | Description |
---|---|
None
|
list[PIDRecord]: A list of PID records created from the provided resources |
Raises:
Type | Description |
---|---|
Exception
|
If an error occurs during the creation of the PID records |
Source code in src/nmr_FAIR_DOs/lib.py
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 |
|
create_pidRecords_from_scratch
async
¶
create_pidRecords_from_scratch(
repos: list[AbstractRepository],
start: datetime = None,
end: datetime = None,
dryrun: bool = False,
) -> list[PIDRecord]
Create PID records from scratch for the given time frame or all available URLs if no time frame is given.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repos |
list[AbstractRepository]
|
The repositories to create PID records for. If None, all available repositories are used. |
required |
start |
datetime
|
The start of the time frame. If None, all available URLs are used. |
None
|
end |
datetime
|
The end of the time frame. If None, all available URLs are used. |
None
|
dryrun |
bool
|
If true, the PID records will not be created in TPM or Elasticsearch |
False
|
Returns:
Type | Description |
---|---|
list[PIDRecord]
|
list[PIDRecord]: A list of PID records created from scratch |
Raises:
Type | Description |
---|---|
Exception
|
If an error occurs during the creation of the PID records |
Source code in src/nmr_FAIR_DOs/lib.py
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 |
|
add_all_existing_pidRecords_to_elasticsearch
async
¶
add_all_existing_pidRecords_to_elasticsearch(
fromFile: str = None,
) -> None
Add all existing PID records to Elasticsearch. If fromFile is not None, the PID records will be read from a file instead of the Typed PID-Maker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fromFile |
bool
|
If true, the PID records will be read from a file instead of the Typed PID-Maker. Default is None. |
None
|
Raises:
Type | Description |
---|---|
Exception
|
If an error occurs during the addition of the PID records to Elasticsearch |
Source code in src/nmr_FAIR_DOs/lib.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 |
|
extractBiggestFAIRDO ¶
extractBiggestFAIRDO(
records: list[PIDRecord],
) -> PIDRecord | None
Extract the biggest FAIR-DO from a list of PID records. The biggest FAIR-DO is the PID record with the most entries (even if they are from the same data type).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
list[PIDRecord]
|
The list of PID records to extract the biggest FAIR-DO from |
required |
Returns:
Name | Type | Description |
---|---|---|
PIDRecord |
PIDRecord | None
|
The biggest FAIR-DO record from the list of PID records |
Source code in src/nmr_FAIR_DOs/lib.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
|
extractRecordWithMostDataTypes ¶
extractRecordWithMostDataTypes(
records: list[PIDRecord],
) -> PIDRecord | None
Extract the PID record with the most different data types from a list of PID records. The PID record with the most different data types is the PID record with the most different keys in its entries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
list[PIDRecord]
|
The list of PID records to extract the PID record with the most different data types from |
required |
Returns:
Name | Type | Description |
---|---|---|
PIDRecord |
PIDRecord | None
|
The PID record with the most different data types from the list of PID records |
Source code in src/nmr_FAIR_DOs/lib.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|