{ "cells": [ { "cell_type": "code", "execution_count": 9, "id": "566afa18", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gc\n", "gc.collect()" ] }, { "cell_type": "code", "execution_count": 93, "id": "52d4f4de", "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 12, "id": "f6a787f6", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "abd16a3416924e40af56ce286f68f8a6", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/6981 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import os\n", "import pandas as pd\n", "import json\n", "from tqdm.auto import tqdm\n", "# Specify the path to the folder containing the JSON files\n", "folder_path = r'D:\\Xelp_work\\FSL Project\\Sprint_2\\HCFA_data\\donut_data\\valid\\key'\n", "\n", "# Initialize an empty DataFrame\n", "master_df = pd.DataFrame()\n", "\n", "# Function to split and expand rows based on the Value column\n", "master_df = pd.DataFrame()\n", "\n", "# Function to split and expand rows based on the Value column\n", "def split_and_expand(row):\n", " keys = [row['KeyName']] * len(row['Value'].split(';'))\n", " values = row['Value'].split(';')\n", " filenames = [row['FileName']] * len(values) # Ensure FileName is carried over\n", " return pd.DataFrame({'FileName': filenames, 'KeyName': keys, 'Value': values})\n", "\n", "# Iterate through all the JSON files in the folder\n", "# for filename in tqdm(os.listdir(folder_path)):\n", "# if filename.endswith('.json'):\n", "# file_path = os.path.join(folder_path, filename)\n", " \n", "# # Read the JSON file\n", "# with open(file_path, 'r') as file:\n", "# data = json.load(file)\n", "# # Convert the JSON data into a DataFrame with columns FileName, KeyName, and Value\n", "# rows = []\n", "# for key, value in data.items():\n", "# rows.append({'FileName': os.path.splitext(filename)[0], 'KeyName': key, 'Value': value})\n", "# df = pd.DataFrame(rows)\n", "# # Apply split_and_expand to each row and combine the results\n", "# expanded_df = df.apply(lambda row: split_and_expand(row), axis=1)\n", "# # Concatenate the expanded dataframes into one DataFrame\n", "# expanded_df = pd.concat(expanded_df.values, ignore_index=True)\n", "# # Append the DataFrame to the master DataFrame\n", "# master_df = pd.concat([master_df, expanded_df], ignore_index=True)" ] }, { "cell_type": "code", "execution_count": 20, "id": "b3cce963", "metadata": {}, "outputs": [], "source": [ "master_df['FileName'] = master_df['FileName'].apply(lambda x: f\"{x}.tiff\")" ] }, { "cell_type": "code", "execution_count": 21, "id": "d718a7b6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6981" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df['FileName'].nunique()" ] }, { "cell_type": "code", "execution_count": 22, "id": "8adccea6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'BSC134A9O003_000_HCFA.tiff'" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df['FileName'][0]" ] }, { "cell_type": "code", "execution_count": 76, "id": "cff6418d", "metadata": {}, "outputs": [], "source": [ "# master_df.to_parquet(r\"D:\\Xelp_work\\FSL Project\\Sprint_2\\HCFA_Results\\Ground_truth_from_Json.parquet\", index=False)" ] }, { "cell_type": "code", "execution_count": 94, "id": "f22688ab", "metadata": {}, "outputs": [], "source": [ "master_df = pd.read_parquet(r\"D:\\Xelp_work\\FSL Project\\Sprint_2\\HCFA_Results\\Ground_truth_from_Json.parquet\")\n", "Extraction_data = pd.read_parquet(r\"D:\\Xelp_work\\FSL Project\\Sprint_2\\HCFA_Results\\HCFA_Validation_data_results.parquet\")" ] }, { "cell_type": "code", "execution_count": 95, "id": "07be99c3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Index(['FileName', 'KeyName', 'Value'], dtype='object'),\n", " Index(['Field_Name', 'Value', 'Image_Name'], dtype='object'))" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df.columns, Extraction_data.columns" ] }, { "cell_type": "code", "execution_count": 96, "id": "de0834fa", "metadata": {}, "outputs": [], "source": [ "Extraction_data.rename(columns={'Image_Name': 'FileName'}, inplace=True)\n", "# Rename Field_Name to KeyName in Extraction_data to match master_df\n", "Extraction_data.rename(columns={'Field_Name': 'KeyName'}, inplace=True)\n", "# Rename Value columns for clarity\n", "Extraction_data.rename(columns={'Value': 'XELP_Output'}, inplace=True)\n", "master_df.rename(columns={'Value': 'Ground_truth'}, inplace=True) " ] }, { "cell_type": "code", "execution_count": 113, "id": "f5703737", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((1268666, 3), (1264044, 3))" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df.shape, Extraction_data.shape" ] }, { "cell_type": "code", "execution_count": 97, "id": "237db0d6", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(Index(['FileName', 'KeyName', 'Ground_truth'], dtype='object'),\n", " Index(['KeyName', 'XELP_Output', 'FileName'], dtype='object'))" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "master_df.columns, Extraction_data.columns" ] }, { "cell_type": "code", "execution_count": 165, "id": "273e6bb4", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 165, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gc.collect()" ] }, { "cell_type": "code", "execution_count": 186, "id": "89bf0570", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████████████████████████████████████████████████████████████████████████| 6981/6981 [08:14<00:00, 14.13it/s]\n" ] }, { "data": { "text/html": [ "
\n", " | FileName | \n", "KeyName | \n", "Ground_truth | \n", "XELP_Output | \n", "
---|---|---|---|---|
0 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "1A_PriInsIDNumber | \n", "R6J588215755 | \n", "R6J588215755 | \n", "
1 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "2_PatFullName | \n", "SUMANTRI, TEGUH | \n", "SUMANTRI, TEGUH | \n", "
2 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "3_PatDOB | \n", "10151973 | \n", "10151973 | \n", "
3 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatAddr1 | \n", "14360 VOSE ST APT219 | \n", "14360 VOSE ST APT219 | \n", "
4 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatCity | \n", "VAN NUYS | \n", "VAN NUYS | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1270014 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesEndTime | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270015 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesTotalTime | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270016 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesTotalMin | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270017 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesMod | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270018 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesUnits | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270019 rows × 4 columns
\n", "\n", " | FileName | \n", "KeyName | \n", "Ground_truth | \n", "XELP_Output | \n", "
---|---|---|---|---|
0 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "1A_PriInsIDNumber | \n", "R6J588215755 | \n", "R6J588215755 | \n", "
1 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "2_PatFullName | \n", "SUMANTRI, TEGUH | \n", "SUMANTRI, TEGUH | \n", "
2 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "3_PatDOB | \n", "10151973 | \n", "10151973 | \n", "
3 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatAddr1 | \n", "14360 VOSE ST APT219 | \n", "14360 VOSE ST APT219 | \n", "
4 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatCity | \n", "VAN NUYS | \n", "VAN NUYS | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1270014 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesEndTime | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270015 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesTotalTime | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270016 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesTotalMin | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270017 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesMod | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270018 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesUnits | \n", "[BLANK] | \n", "[BLANK] | \n", "
1270019 rows × 4 columns
\n", "\n", " | FileName | \n", "KeyName | \n", "Ground_truth | \n", "XELP_Output | \n", "Matching | \n", "
---|---|---|---|---|---|
0 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "1A_PriInsIDNumber | \n", "R6J588215755 | \n", "R6J588215755 | \n", "1 | \n", "
1 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "2_PatFullName | \n", "SUMANTRI, TEGUH | \n", "SUMANTRI, TEGUH | \n", "1 | \n", "
2 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "3_PatDOB | \n", "10151973 | \n", "10151973 | \n", "1 | \n", "
3 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatAddr1 | \n", "14360 VOSE ST APT219 | \n", "14360 VOSE ST APT219 | \n", "1 | \n", "
4 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatCity | \n", "VAN NUYS | \n", "VAN NUYS | \n", "1 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1269996 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "10A_PatConditionEmpN | \n", "X | \n", "X | \n", "1 | \n", "
1269998 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "10B_PatConditionAutoN | \n", "X | \n", "X | \n", "1 | \n", "
1270000 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "10C_PatConditionOtherN | \n", "X | \n", "X | \n", "1 | \n", "
1270010 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "25_BillProvEIN | \n", "X | \n", "X | \n", "1 | \n", "
1270011 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "27_AcceptAssignmentY | \n", "X | \n", "X | \n", "1 | \n", "
443019 rows × 5 columns
\n", "\n", " | FileName | \n", "KeyName | \n", "Ground_truth | \n", "XELP_Output | \n", "Matching | \n", "
---|
\n", " | FileName | \n", "KeyName | \n", "Ground_truth | \n", "XELP_Output | \n", "Matching | \n", "
---|---|---|---|---|---|
7 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "5_PatPhoneNumber | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
13 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "7_PriInsPhoneNumber | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
33 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "16_PatUTWToDate | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
38 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "17_RefProvOrgName | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
42 | \n", "BSC134A9O003_000_HCFA.tiff | \n", "20_OSLabCharges | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
1270004 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "11D_PriInsOtherPlanN | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
1270005 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "19_LocalUse | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
1270007 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "20_OSLabY | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
1270008 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "20_OSLabN | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
1270017 | \n", "PHP8843RO035_000_HCFA.tiff | \n", "24_AnesMod | \n", "[BLANK] | \n", "[BLANK] | \n", "1 | \n", "
136532 rows × 5 columns
\n", "