Added Custom Serializer for Table enrichment

Signed-off-by: Nikhil Khandelwal <nikhil.khandelwal3@ibm.com>
This commit is contained in:
Nikhil Khandelwal 2025-05-15 00:26:57 +05:30
parent 718633cdec
commit 25856e1392

View File

@ -479,7 +479,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -528,7 +528,7 @@
" # appending annotations:\n", " # appending annotations:\n",
" for annotation in item.annotations:\n", " for annotation in item.annotations:\n",
" if isinstance(annotation, PictureDescriptionData):\n", " if isinstance(annotation, PictureDescriptionData):\n",
" text_parts.append(f\"<!-- Picture description: {annotation.text} -->\")\n", " text_parts.append(f\"{item.self_ref}\\n<!-- Picture description: {annotation.text} -->\")\n",
"\n", "\n",
" text_res = (separator or \"\\n\").join(text_parts)\n", " text_res = (separator or \"\\n\").join(text_parts)\n",
" return create_ser_result(text=text_res, span_source=item)" " return create_ser_result(text=text_res, span_source=item)"
@ -684,7 +684,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -733,7 +733,7 @@
" # appending annotations:\n", " # appending annotations:\n",
" for annotation in item.annotations:\n", " for annotation in item.annotations:\n",
" if isinstance(annotation, PictureDescriptionData):\n", " if isinstance(annotation, PictureDescriptionData):\n",
" text_parts.append(f\"\\n<!-- Table description: {annotation.text} -->\")\n", " text_parts.append(f\"\\n{item.self_ref}\\n<!-- Table description: {annotation.text} -->\")\n",
"\n", "\n",
" text_res = (separator or \"\\n\").join(text_parts)\n", " text_res = (separator or \"\\n\").join(text_parts)\n",
" return create_ser_result(text=text_res, span_source=item)" " return create_ser_result(text=text_res, span_source=item)"
@ -741,7 +741,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -759,6 +759,7 @@
"│ | Starbucks 2022 | What was the total energy con- sumption in 2021? | According to the table, the total energy consumption in 2021 was 2,491,543 MWh. | │\n", "│ | Starbucks 2022 | What was the total energy con- sumption in 2021? | According to the table, the total energy consumption in 2021 was 2,491,543 MWh. | │\n",
"│ | Starbucks 2022 | How much packaging material was made from renewable mate- rials? | According to the given data, 31% of packaging materials were made from recycled or renewable materials in FY22. | │\n", "│ | Starbucks 2022 | How much packaging material was made from renewable mate- rials? | According to the given data, 31% of packaging materials were made from recycled or renewable materials in FY22. | │\n",
"│ │\n", "│ │\n",
"│ #/tables/0 │\n",
"│ &lt;!-- Table description: The image is a bar chart that shows the number of hours spent on employee learning in 2021. The x-axis represents the number of hours, ranging from 0 to 22.5 million, while the │\n", "│ &lt;!-- Table description: The image is a bar chart that shows the number of hours spent on employee learning in 2021. The x-axis represents the number of hours, ranging from 0 to 22.5 million, while the │\n",
"│ y-axis represents the number of hours, ranging from 0 to 22.5 million. The chart shows that the number of hours spent on employee learning increased from 2021 to 2022, with the highest number of hours spent │\n", "│ y-axis represents the number of hours, ranging from 0 to 22.5 million. The chart shows that the number of hours spent on employee learning increased from 2021 to 2022, with the highest number of hours spent │\n",
"│ on employee learning in 2022. │\n", "│ on employee learning in 2022. │\n",
@ -805,6 +806,7 @@
"│ | Starbucks 2022 | What was the total energy con- sumption in 2021? | According to the table, the total energy consumption in 2021 was 2,491,543 MWh. | │\n", "│ | Starbucks 2022 | What was the total energy con- sumption in 2021? | According to the table, the total energy consumption in 2021 was 2,491,543 MWh. | │\n",
"│ | Starbucks 2022 | How much packaging material was made from renewable mate- rials? | According to the given data, 31% of packaging materials were made from recycled or renewable materials in FY22. | │\n", "│ | Starbucks 2022 | How much packaging material was made from renewable mate- rials? | According to the given data, 31% of packaging materials were made from recycled or renewable materials in FY22. | │\n",
"│ │\n", "│ │\n",
"│ #/tables/0 │\n",
"│ <!-- Table description: The image is a bar chart that shows the number of hours spent on employee learning in 2021. The x-axis represents the number of hours, ranging from 0 to 22.5 million, while the │\n", "│ <!-- Table description: The image is a bar chart that shows the number of hours spent on employee learning in 2021. The x-axis represents the number of hours, ranging from 0 to 22.5 million, while the │\n",
"│ y-axis represents the number of hours, ranging from 0 to 22.5 million. The chart shows that the number of hours spent on employee learning increased from 2021 to 2022, with the highest number of hours spent │\n", "│ y-axis represents the number of hours, ranging from 0 to 22.5 million. The chart shows that the number of hours spent on employee learning increased from 2021 to 2022, with the highest number of hours spent │\n",
"│ on employee learning in 2022. │\n", "│ on employee learning in 2022. │\n",