Speed up owner match process
Browse filesIt's also completed in the notebook (at end).
eol_realign/notebooks/catalog-cargo-manifest_test.ipynb
CHANGED
|
@@ -354,7 +354,7 @@
|
|
| 354 |
},
|
| 355 |
{
|
| 356 |
"cell_type": "code",
|
| 357 |
-
"execution_count":
|
| 358 |
"metadata": {},
|
| 359 |
"outputs": [
|
| 360 |
{
|
|
@@ -368,7 +368,7 @@
|
|
| 368 |
" dtype='object')"
|
| 369 |
]
|
| 370 |
},
|
| 371 |
-
"execution_count":
|
| 372 |
"metadata": {},
|
| 373 |
"output_type": "execute_result"
|
| 374 |
}
|
|
@@ -465,6 +465,360 @@
|
|
| 465 |
"Only 6,219,674 of our 6,250,420 images were able to be pulled through the combined manifests."
|
| 466 |
]
|
| 467 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
{
|
| 469 |
"cell_type": "code",
|
| 470 |
"execution_count": null,
|
|
|
|
| 354 |
},
|
| 355 |
{
|
| 356 |
"cell_type": "code",
|
| 357 |
+
"execution_count": 3,
|
| 358 |
"metadata": {},
|
| 359 |
"outputs": [
|
| 360 |
{
|
|
|
|
| 368 |
" dtype='object')"
|
| 369 |
]
|
| 370 |
},
|
| 371 |
+
"execution_count": 3,
|
| 372 |
"metadata": {},
|
| 373 |
"output_type": "execute_result"
|
| 374 |
}
|
|
|
|
| 465 |
"Only 6,219,674 of our 6,250,420 images were able to be pulled through the combined manifests."
|
| 466 |
]
|
| 467 |
},
|
| 468 |
+
{
|
| 469 |
+
"cell_type": "markdown",
|
| 470 |
+
"metadata": {},
|
| 471 |
+
"source": [
|
| 472 |
+
"### Align Owners to Manifest"
|
| 473 |
+
]
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"cell_type": "code",
|
| 477 |
+
"execution_count": 7,
|
| 478 |
+
"metadata": {},
|
| 479 |
+
"outputs": [],
|
| 480 |
+
"source": [
|
| 481 |
+
"owner_df = pd.read_csv(\"../data/media_manifest_missing_licenses_jul26_owners.csv\",\n",
|
| 482 |
+
" low_memory=False,\n",
|
| 483 |
+
" dtype={\"EOL content ID\": \"int64\", \"EOL page ID\": \"int64\"},)"
|
| 484 |
+
]
|
| 485 |
+
},
|
| 486 |
+
{
|
| 487 |
+
"cell_type": "markdown",
|
| 488 |
+
"metadata": {},
|
| 489 |
+
"source": [
|
| 490 |
+
"try merge then fill and concatenate."
|
| 491 |
+
]
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"cell_type": "code",
|
| 495 |
+
"execution_count": 8,
|
| 496 |
+
"metadata": {},
|
| 497 |
+
"outputs": [
|
| 498 |
+
{
|
| 499 |
+
"name": "stdout",
|
| 500 |
+
"output_type": "stream",
|
| 501 |
+
"text": [
|
| 502 |
+
"['filename_manifest', 'md5_combined_manifest', 'combined_id_manifest_redownload', 'eol_content_id', 'eol_page_id', 'medium_source_url', 'eol_full_size_copy_url', 'license_name', 'copyright_owner', 'expected_image_filename', 'source_0706', 'source_0726', 'source_1206', 'combined_id_full_manifest']\n",
|
| 503 |
+
"['EOL content ID', 'EOL page ID', 'Medium Source URL', 'EOL Full-Size Copy URL', 'License Name', 'Copyright Owner', 'license_link', 'title']\n"
|
| 504 |
+
]
|
| 505 |
+
}
|
| 506 |
+
],
|
| 507 |
+
"source": [
|
| 508 |
+
"print(list(manifests.columns))\n",
|
| 509 |
+
"print(list(owner_df.columns))"
|
| 510 |
+
]
|
| 511 |
+
},
|
| 512 |
+
{
|
| 513 |
+
"cell_type": "code",
|
| 514 |
+
"execution_count": 23,
|
| 515 |
+
"metadata": {},
|
| 516 |
+
"outputs": [
|
| 517 |
+
{
|
| 518 |
+
"name": "stdout",
|
| 519 |
+
"output_type": "stream",
|
| 520 |
+
"text": [
|
| 521 |
+
"There are 12330062 entries in the combined manifest\n",
|
| 522 |
+
"There are 632043 entries in the owner match CSV\n"
|
| 523 |
+
]
|
| 524 |
+
}
|
| 525 |
+
],
|
| 526 |
+
"source": [
|
| 527 |
+
"print(f\"There are {manifests.shape[0]} entries in the combined manifest\")\n",
|
| 528 |
+
"print(f\"There are {owner_df.shape[0]} entries in the owner match CSV\")"
|
| 529 |
+
]
|
| 530 |
+
},
|
| 531 |
+
{
|
| 532 |
+
"cell_type": "code",
|
| 533 |
+
"execution_count": 9,
|
| 534 |
+
"metadata": {},
|
| 535 |
+
"outputs": [],
|
| 536 |
+
"source": [
|
| 537 |
+
"owner_df[\"combined_id_owner\"] = owner_df[\"EOL content ID\"].astype(str) + \"_\" + owner_df[\"EOL page ID\"].astype(str)\n"
|
| 538 |
+
]
|
| 539 |
+
},
|
| 540 |
+
{
|
| 541 |
+
"cell_type": "code",
|
| 542 |
+
"execution_count": 15,
|
| 543 |
+
"metadata": {},
|
| 544 |
+
"outputs": [
|
| 545 |
+
{
|
| 546 |
+
"name": "stdout",
|
| 547 |
+
"output_type": "stream",
|
| 548 |
+
"text": [
|
| 549 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 550 |
+
"RangeIndex: 630056 entries, 0 to 630055\n",
|
| 551 |
+
"Data columns (total 23 columns):\n",
|
| 552 |
+
" # Column Non-Null Count Dtype \n",
|
| 553 |
+
"--- ------ -------------- ----- \n",
|
| 554 |
+
" 0 EOL content ID 630056 non-null int64 \n",
|
| 555 |
+
" 1 EOL page ID 630056 non-null int64 \n",
|
| 556 |
+
" 2 Medium Source URL 630056 non-null object\n",
|
| 557 |
+
" 3 EOL Full-Size Copy URL 630056 non-null object\n",
|
| 558 |
+
" 4 License Name 630056 non-null object\n",
|
| 559 |
+
" 5 Copyright Owner 611829 non-null object\n",
|
| 560 |
+
" 6 license_link 619741 non-null object\n",
|
| 561 |
+
" 7 title 604447 non-null object\n",
|
| 562 |
+
" 8 combined_id_owner 630056 non-null object\n",
|
| 563 |
+
" 9 filename_manifest 630056 non-null object\n",
|
| 564 |
+
" 10 md5_combined_manifest 630056 non-null object\n",
|
| 565 |
+
" 11 combined_id_manifest_redownload 630056 non-null object\n",
|
| 566 |
+
" 12 eol_content_id 630056 non-null int64 \n",
|
| 567 |
+
" 13 eol_page_id 630056 non-null int64 \n",
|
| 568 |
+
" 14 medium_source_url 630056 non-null object\n",
|
| 569 |
+
" 15 eol_full_size_copy_url 630056 non-null object\n",
|
| 570 |
+
" 16 license_name 630056 non-null object\n",
|
| 571 |
+
" 17 copyright_owner 0 non-null object\n",
|
| 572 |
+
" 18 expected_image_filename 630056 non-null object\n",
|
| 573 |
+
" 19 source_0706 630056 non-null bool \n",
|
| 574 |
+
" 20 source_0726 630056 non-null bool \n",
|
| 575 |
+
" 21 source_1206 630056 non-null bool \n",
|
| 576 |
+
" 22 combined_id_full_manifest 630056 non-null object\n",
|
| 577 |
+
"dtypes: bool(3), int64(4), object(16)\n",
|
| 578 |
+
"memory usage: 97.9+ MB\n"
|
| 579 |
+
]
|
| 580 |
+
}
|
| 581 |
+
],
|
| 582 |
+
"source": [
|
| 583 |
+
"owners_manifest = pd.merge(owner_df,\n",
|
| 584 |
+
" manifests,\n",
|
| 585 |
+
" left_on=\"combined_id_owner\",\n",
|
| 586 |
+
" right_on = \"combined_id_full_manifest\",\n",
|
| 587 |
+
" how = \"inner\")\n",
|
| 588 |
+
"owners_manifest.info()"
|
| 589 |
+
]
|
| 590 |
+
},
|
| 591 |
+
{
|
| 592 |
+
"cell_type": "code",
|
| 593 |
+
"execution_count": 16,
|
| 594 |
+
"metadata": {},
|
| 595 |
+
"outputs": [
|
| 596 |
+
{
|
| 597 |
+
"name": "stdout",
|
| 598 |
+
"output_type": "stream",
|
| 599 |
+
"text": [
|
| 600 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 601 |
+
"RangeIndex: 630056 entries, 0 to 630055\n",
|
| 602 |
+
"Data columns (total 23 columns):\n",
|
| 603 |
+
" # Column Non-Null Count Dtype \n",
|
| 604 |
+
"--- ------ -------------- ----- \n",
|
| 605 |
+
" 0 EOL content ID 630056 non-null int64 \n",
|
| 606 |
+
" 1 EOL page ID 630056 non-null int64 \n",
|
| 607 |
+
" 2 Medium Source URL 630056 non-null object\n",
|
| 608 |
+
" 3 EOL Full-Size Copy URL 630056 non-null object\n",
|
| 609 |
+
" 4 License Name 630056 non-null object\n",
|
| 610 |
+
" 5 Copyright Owner 611829 non-null object\n",
|
| 611 |
+
" 6 license_link 619741 non-null object\n",
|
| 612 |
+
" 7 title 604447 non-null object\n",
|
| 613 |
+
" 8 combined_id_owner 630056 non-null object\n",
|
| 614 |
+
" 9 filename_manifest 630056 non-null object\n",
|
| 615 |
+
" 10 md5_combined_manifest 630056 non-null object\n",
|
| 616 |
+
" 11 combined_id_manifest_redownload 630056 non-null object\n",
|
| 617 |
+
" 12 eol_content_id 630056 non-null int64 \n",
|
| 618 |
+
" 13 eol_page_id 630056 non-null int64 \n",
|
| 619 |
+
" 14 medium_source_url 630056 non-null object\n",
|
| 620 |
+
" 15 eol_full_size_copy_url 630056 non-null object\n",
|
| 621 |
+
" 16 license_name 630056 non-null object\n",
|
| 622 |
+
" 17 copyright_owner 611829 non-null object\n",
|
| 623 |
+
" 18 expected_image_filename 630056 non-null object\n",
|
| 624 |
+
" 19 source_0706 630056 non-null bool \n",
|
| 625 |
+
" 20 source_0726 630056 non-null bool \n",
|
| 626 |
+
" 21 source_1206 630056 non-null bool \n",
|
| 627 |
+
" 22 combined_id_full_manifest 630056 non-null object\n",
|
| 628 |
+
"dtypes: bool(3), int64(4), object(16)\n",
|
| 629 |
+
"memory usage: 97.9+ MB\n"
|
| 630 |
+
]
|
| 631 |
+
}
|
| 632 |
+
],
|
| 633 |
+
"source": [
|
| 634 |
+
"owners_manifest[\"copyright_owner\"] = owners_manifest[\"Copyright Owner\"]\n",
|
| 635 |
+
"owners_manifest.info(show_counts=True)"
|
| 636 |
+
]
|
| 637 |
+
},
|
| 638 |
+
{
|
| 639 |
+
"cell_type": "code",
|
| 640 |
+
"execution_count": 17,
|
| 641 |
+
"metadata": {},
|
| 642 |
+
"outputs": [
|
| 643 |
+
{
|
| 644 |
+
"data": {
|
| 645 |
+
"text/plain": [
|
| 646 |
+
"Index(['filename_manifest', 'md5_combined_manifest',\n",
|
| 647 |
+
" 'combined_id_manifest_redownload', 'eol_content_id', 'eol_page_id',\n",
|
| 648 |
+
" 'medium_source_url', 'eol_full_size_copy_url', 'license_name',\n",
|
| 649 |
+
" 'copyright_owner', 'expected_image_filename', 'source_0706',\n",
|
| 650 |
+
" 'source_0726', 'source_1206', 'combined_id_full_manifest', 'title'],\n",
|
| 651 |
+
" dtype='object')"
|
| 652 |
+
]
|
| 653 |
+
},
|
| 654 |
+
"execution_count": 17,
|
| 655 |
+
"metadata": {},
|
| 656 |
+
"output_type": "execute_result"
|
| 657 |
+
}
|
| 658 |
+
],
|
| 659 |
+
"source": [
|
| 660 |
+
"license_cols = list(manifests.columns)\n",
|
| 661 |
+
"license_cols.append(\"title\")\n",
|
| 662 |
+
"owners_manifest = owners_manifest[license_cols]\n",
|
| 663 |
+
"owners_manifest.columns"
|
| 664 |
+
]
|
| 665 |
+
},
|
| 666 |
+
{
|
| 667 |
+
"cell_type": "code",
|
| 668 |
+
"execution_count": 13,
|
| 669 |
+
"metadata": {},
|
| 670 |
+
"outputs": [
|
| 671 |
+
{
|
| 672 |
+
"data": {
|
| 673 |
+
"text/plain": [
|
| 674 |
+
"630056"
|
| 675 |
+
]
|
| 676 |
+
},
|
| 677 |
+
"execution_count": 13,
|
| 678 |
+
"metadata": {},
|
| 679 |
+
"output_type": "execute_result"
|
| 680 |
+
}
|
| 681 |
+
],
|
| 682 |
+
"source": [
|
| 683 |
+
"rematched_owner_ids = list(owners_manifest.combined_id_full_manifest.unique())\n",
|
| 684 |
+
"len(rematched_owner_ids)"
|
| 685 |
+
]
|
| 686 |
+
},
|
| 687 |
+
{
|
| 688 |
+
"cell_type": "code",
|
| 689 |
+
"execution_count": 14,
|
| 690 |
+
"metadata": {},
|
| 691 |
+
"outputs": [
|
| 692 |
+
{
|
| 693 |
+
"data": {
|
| 694 |
+
"text/plain": [
|
| 695 |
+
"(11700006, 14)"
|
| 696 |
+
]
|
| 697 |
+
},
|
| 698 |
+
"execution_count": 14,
|
| 699 |
+
"metadata": {},
|
| 700 |
+
"output_type": "execute_result"
|
| 701 |
+
}
|
| 702 |
+
],
|
| 703 |
+
"source": [
|
| 704 |
+
"un_matched_owner_manifest = manifests.loc[~manifests.combined_id_full_manifest.isin(rematched_owner_ids)]\n",
|
| 705 |
+
"un_matched_owner_manifest.shape"
|
| 706 |
+
]
|
| 707 |
+
},
|
| 708 |
+
{
|
| 709 |
+
"cell_type": "code",
|
| 710 |
+
"execution_count": 18,
|
| 711 |
+
"metadata": {},
|
| 712 |
+
"outputs": [
|
| 713 |
+
{
|
| 714 |
+
"name": "stderr",
|
| 715 |
+
"output_type": "stream",
|
| 716 |
+
"text": [
|
| 717 |
+
"/var/folders/nv/f0fq1p1n1_3b11x579py_0q80000gq/T/ipykernel_4207/1002247400.py:1: SettingWithCopyWarning: \n",
|
| 718 |
+
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
| 719 |
+
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
| 720 |
+
"\n",
|
| 721 |
+
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
| 722 |
+
" un_matched_owner_manifest[\"title\"] = \"not provided\"\n"
|
| 723 |
+
]
|
| 724 |
+
}
|
| 725 |
+
],
|
| 726 |
+
"source": [
|
| 727 |
+
"un_matched_owner_manifest[\"title\"] = \"not provided\""
|
| 728 |
+
]
|
| 729 |
+
},
|
| 730 |
+
{
|
| 731 |
+
"cell_type": "code",
|
| 732 |
+
"execution_count": 19,
|
| 733 |
+
"metadata": {},
|
| 734 |
+
"outputs": [
|
| 735 |
+
{
|
| 736 |
+
"name": "stdout",
|
| 737 |
+
"output_type": "stream",
|
| 738 |
+
"text": [
|
| 739 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 740 |
+
"RangeIndex: 12330062 entries, 0 to 12330061\n",
|
| 741 |
+
"Data columns (total 15 columns):\n",
|
| 742 |
+
" # Column Non-Null Count Dtype \n",
|
| 743 |
+
"--- ------ -------------- ----- \n",
|
| 744 |
+
" 0 filename_manifest 12330062 non-null object\n",
|
| 745 |
+
" 1 md5_combined_manifest 12330062 non-null object\n",
|
| 746 |
+
" 2 combined_id_manifest_redownload 12330062 non-null object\n",
|
| 747 |
+
" 3 eol_content_id 12330062 non-null int64 \n",
|
| 748 |
+
" 4 eol_page_id 12330062 non-null int64 \n",
|
| 749 |
+
" 5 medium_source_url 12330062 non-null object\n",
|
| 750 |
+
" 6 eol_full_size_copy_url 12330062 non-null object\n",
|
| 751 |
+
" 7 license_name 12330062 non-null object\n",
|
| 752 |
+
" 8 copyright_owner 11544885 non-null object\n",
|
| 753 |
+
" 9 expected_image_filename 12330062 non-null object\n",
|
| 754 |
+
" 10 source_0706 12330062 non-null bool \n",
|
| 755 |
+
" 11 source_0726 12330062 non-null bool \n",
|
| 756 |
+
" 12 source_1206 12330062 non-null bool \n",
|
| 757 |
+
" 13 combined_id_full_manifest 12330062 non-null object\n",
|
| 758 |
+
" 14 title 12304453 non-null object\n",
|
| 759 |
+
"dtypes: bool(3), int64(2), object(10)\n",
|
| 760 |
+
"memory usage: 1.1+ GB\n"
|
| 761 |
+
]
|
| 762 |
+
}
|
| 763 |
+
],
|
| 764 |
+
"source": [
|
| 765 |
+
"full_owner_manifest = pd.concat([un_matched_owner_manifest, owners_manifest], ignore_index=True)\n",
|
| 766 |
+
"full_owner_manifest.info(show_counts = True)"
|
| 767 |
+
]
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"cell_type": "code",
|
| 771 |
+
"execution_count": 20,
|
| 772 |
+
"metadata": {},
|
| 773 |
+
"outputs": [
|
| 774 |
+
{
|
| 775 |
+
"name": "stdout",
|
| 776 |
+
"output_type": "stream",
|
| 777 |
+
"text": [
|
| 778 |
+
"Licenses still missing Copyright Owners: \n",
|
| 779 |
+
" license_name\n",
|
| 780 |
+
"cc-by-3.0 262894\n",
|
| 781 |
+
"cc-publicdomain 262803\n",
|
| 782 |
+
"cc-by-nc-sa-3.0 122493\n",
|
| 783 |
+
"cc-by-sa-3.0 93303\n",
|
| 784 |
+
"No known copyright restrictions 31025\n",
|
| 785 |
+
"cc-by-nc 12619\n",
|
| 786 |
+
"cc-0-1.0 32\n",
|
| 787 |
+
"cc-by-nc-2.0 5\n",
|
| 788 |
+
"cc-by-nc-4.0 2\n",
|
| 789 |
+
"cc-by-nc-sa 1\n",
|
| 790 |
+
"Name: count, dtype: int64\n"
|
| 791 |
+
]
|
| 792 |
+
}
|
| 793 |
+
],
|
| 794 |
+
"source": [
|
| 795 |
+
"print(\n",
|
| 796 |
+
" \"Licenses still missing Copyright Owners: \\n\",\n",
|
| 797 |
+
" full_owner_manifest.loc[\n",
|
| 798 |
+
" full_owner_manifest[\"copyright_owner\"].isna(), \"license_name\"\n",
|
| 799 |
+
" ].value_counts(),\n",
|
| 800 |
+
" )"
|
| 801 |
+
]
|
| 802 |
+
},
|
| 803 |
+
{
|
| 804 |
+
"cell_type": "code",
|
| 805 |
+
"execution_count": 21,
|
| 806 |
+
"metadata": {},
|
| 807 |
+
"outputs": [],
|
| 808 |
+
"source": [
|
| 809 |
+
"full_owner_manifest[\"copyright_owner\"].fillna(\"not provided\", inplace=True)\n",
|
| 810 |
+
"full_owner_manifest[\"title\"].fillna(\"not provided\", inplace=True)"
|
| 811 |
+
]
|
| 812 |
+
},
|
| 813 |
+
{
|
| 814 |
+
"cell_type": "code",
|
| 815 |
+
"execution_count": 22,
|
| 816 |
+
"metadata": {},
|
| 817 |
+
"outputs": [],
|
| 818 |
+
"source": [
|
| 819 |
+
"full_owner_manifest.to_csv(\"../data/full_owner_manifest.csv\", index = False)"
|
| 820 |
+
]
|
| 821 |
+
},
|
| 822 |
{
|
| 823 |
"cell_type": "code",
|
| 824 |
"execution_count": null,
|
eol_realign/scripts/make_licenses.py
CHANGED
|
@@ -57,7 +57,8 @@ def main(src_csv, dest_dir):
|
|
| 57 |
if "license_name" not in df_cols:
|
| 58 |
sys.exit("Source CSV does not have a column labeled License Name or license_name.")
|
| 59 |
license_col = "license_name"
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
# Check filepath given by user
|
| 63 |
dest_dir_path = Path(dest_dir)
|
|
|
|
| 57 |
if "license_name" not in df_cols:
|
| 58 |
sys.exit("Source CSV does not have a column labeled License Name or license_name.")
|
| 59 |
license_col = "license_name"
|
| 60 |
+
else:
|
| 61 |
+
license_col = "License Name"
|
| 62 |
|
| 63 |
# Check filepath given by user
|
| 64 |
dest_dir_path = Path(dest_dir)
|
eol_realign/scripts/match_owners.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
from tqdm import tqdm
|
| 3 |
from pathlib import Path
|
| 4 |
import argparse
|
| 5 |
import sys
|
| 6 |
|
| 7 |
-
#
|
| 8 |
# It is intended to just add the extra licensing information to the combined manifest
|
| 9 |
# Owner fix file: https://huggingface.co/datasets/imageomics/eol/blob/main/owners_info_fix/media_manifest_missing_licenses_jul26_owners.csv
|
| 10 |
MANIFEST_PATH = "data/combined_manifest_with_checksums.csv"
|
|
@@ -24,35 +23,41 @@ def get_owners_titles(manifest, owners):
|
|
| 24 |
|
| 25 |
Returns:
|
| 26 |
--------
|
| 27 |
-
|
|
|
|
| 28 |
"""
|
| 29 |
-
missing_owners = [
|
| 30 |
-
comb_id
|
| 31 |
-
for comb_id in list(
|
| 32 |
-
manifest.loc[manifest["copyright_owner"].isna(), "combined_id_full_manifest"]
|
| 33 |
-
)
|
| 34 |
-
]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Fill null "copyright_owner" and "Title" values with "not provided"
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
return
|
| 56 |
|
| 57 |
|
| 58 |
def update_owners(manifest, owners, filepath):
|
|
@@ -69,11 +74,20 @@ def update_owners(manifest, owners, filepath):
|
|
| 69 |
# EOL content & page IDs read in as int64
|
| 70 |
owners["combined_id_owner"] = owners["EOL content ID"].astype(str) + "_" + owners["EOL page ID"].astype(str)
|
| 71 |
|
| 72 |
-
updated_manifest = get_owners_titles(manifest, owners)
|
| 73 |
|
| 74 |
# Save updated combined manifest file to chosen location
|
| 75 |
updated_manifest.to_csv(filepath, index=False)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
def main(dest_dir):
|
| 79 |
# Read in CSVs
|
|
|
|
| 1 |
import pandas as pd
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
import argparse
|
| 4 |
import sys
|
| 5 |
|
| 6 |
+
# NOTE: column names are hard-coded to the files provided in MANIFEST_PATH & OWNER_PATH
|
| 7 |
# It is intended to just add the extra licensing information to the combined manifest
|
| 8 |
# Owner fix file: https://huggingface.co/datasets/imageomics/eol/blob/main/owners_info_fix/media_manifest_missing_licenses_jul26_owners.csv
|
| 9 |
MANIFEST_PATH = "data/combined_manifest_with_checksums.csv"
|
|
|
|
| 23 |
|
| 24 |
Returns:
|
| 25 |
--------
|
| 26 |
+
full_owner_manifest - Media manifest DataFrame with missing owners resolved.
|
| 27 |
+
num_matched - Number of records matched with the owner fix file.
|
| 28 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# First merge owners
|
| 31 |
+
owners_manifest = pd.merge(owners,
|
| 32 |
+
manifest,
|
| 33 |
+
left_on="combined_id_owner",
|
| 34 |
+
right_on = "combined_id_full_manifest",
|
| 35 |
+
how = "inner")
|
| 36 |
+
|
| 37 |
+
# Set "copyright_owner" column to owners patched in owner CSV
|
| 38 |
+
owners_manifest["copyright_owner"] = owners_manifest["Copyright Owner"]
|
| 39 |
|
| 40 |
+
# Preserve columns that match the combined manifest
|
| 41 |
+
license_cols = list(manifest.columns)
|
| 42 |
+
license_cols.append("title")
|
| 43 |
+
owners_manifest = owners_manifest[license_cols]
|
| 44 |
+
|
| 45 |
+
# Get matched owner IDs
|
| 46 |
+
rematched_owner_ids = list(owners_manifest.combined_id_full_manifest.unique())
|
| 47 |
+
num_matched = len(rematched_owner_ids)
|
| 48 |
+
|
| 49 |
+
# Reduce manifest to just records not matched in owner file
|
| 50 |
+
un_matched_owner_manifest = manifest.loc[~manifest.combined_id_full_manifest.isin(rematched_owner_ids)]
|
| 51 |
+
un_matched_owner_manifest["title"] = "not provided"
|
| 52 |
+
|
| 53 |
+
# Align the matched owners with the unmatched
|
| 54 |
+
full_owner_manifest = pd.concat([un_matched_owner_manifest, owners_manifest], ignore_index=True)
|
| 55 |
|
| 56 |
# Fill null "copyright_owner" and "Title" values with "not provided"
|
| 57 |
+
full_owner_manifest["copyright_owner"].fillna("not provided", inplace=True)
|
| 58 |
+
full_owner_manifest["title"].fillna("not provided", inplace=True)
|
| 59 |
|
| 60 |
+
return full_owner_manifest, num_matched
|
| 61 |
|
| 62 |
|
| 63 |
def update_owners(manifest, owners, filepath):
|
|
|
|
| 74 |
# EOL content & page IDs read in as int64
|
| 75 |
owners["combined_id_owner"] = owners["EOL content ID"].astype(str) + "_" + owners["EOL page ID"].astype(str)
|
| 76 |
|
| 77 |
+
updated_manifest, num_matched = get_owners_titles(manifest, owners)
|
| 78 |
|
| 79 |
# Save updated combined manifest file to chosen location
|
| 80 |
updated_manifest.to_csv(filepath, index=False)
|
| 81 |
|
| 82 |
+
# Print counts of licenses for which owner info was not resolved
|
| 83 |
+
print(f"Of the {manifest.shape[0]} entries in manifest, {num_matched} were matched to the owner fix file.")
|
| 84 |
+
print(
|
| 85 |
+
"Licenses still missing Copyright Owners: \n",
|
| 86 |
+
manifest.loc[
|
| 87 |
+
manifest["copyright_owner"].isna(), "license_name"
|
| 88 |
+
].value_counts(),
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
|
| 92 |
def main(dest_dir):
|
| 93 |
# Read in CSVs
|