Update Tuberculosis_Dataset.py
Browse files- Tuberculosis_Dataset.py +21 -1
Tuberculosis_Dataset.py
CHANGED
@@ -54,8 +54,28 @@ class TuberculosisDataset(GeneratorBasedBuilder):
|
|
54 |
]
|
55 |
|
56 |
def _generate_examples(self, cases_csv, keywords_json, caption_json, images_zip):
|
57 |
-
#
|
|
|
|
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Prepare images
|
60 |
image_filenames = self._prepare_images(images_zip, dl_manager.extracted_path)
|
61 |
|
|
|
54 |
]
|
55 |
|
56 |
def _generate_examples(self, cases_csv, keywords_json, caption_json, images_zip):
|
57 |
+
# Load CSV
|
58 |
+
cases_df = pd.read_csv(cases_csv)
|
59 |
+
cases_df.dropna(subset=['age'], inplace=True)
|
60 |
|
61 |
+
# Load Keywords JSON
|
62 |
+
with open(keywords_json, 'r') as f:
|
63 |
+
keywords_json_data = json.load(f)
|
64 |
+
keywords = pd.json_normalize(keywords_json_data)
|
65 |
+
keywords['keywords'] = keywords['keywords'].apply(lambda x: ', '.join(x) if isinstance(x, list) else x)
|
66 |
+
|
67 |
+
# Load Caption JSON
|
68 |
+
caption_json_data = []
|
69 |
+
with open(caption_json, 'r') as f:
|
70 |
+
for line in f:
|
71 |
+
caption_json_data.append(json.loads(line))
|
72 |
+
caption = pd.json_normalize(caption_json_data)
|
73 |
+
|
74 |
+
# Merge DataFrames
|
75 |
+
merged_df = pd.merge(cases_df, keywords[['pmcid', 'keywords']], left_on='case_id', right_on='pmcid', how='left')
|
76 |
+
merged_df = pd.merge(merged_df, caption[['case_id', 'caption']], on='case_id', how='left')
|
77 |
+
merged_df = merged_df.where(pd.notnull(merged_df), None)
|
78 |
+
merged_df['age'] = merged_df['age'].astype('int8')
|
79 |
# Prepare images
|
80 |
image_filenames = self._prepare_images(images_zip, dl_manager.extracted_path)
|
81 |
|