-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DL
committed
Aug 3, 2024
1 parent
377f827
commit b655b04
Showing
3 changed files
with
230 additions
and
182 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pandas as pd | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class GenericParsedTable(ABC): | ||
def __init__(self, page_number: int): | ||
self.page_num = page_number # Common field | ||
|
||
@property | ||
@abstractmethod | ||
def df(self) -> pd.DataFrame: | ||
"""Returns Pandas DF corresponding to a table""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def caption(self) -> str: | ||
"""Returns caption of the table""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def xml(self) -> str: | ||
"""Returns xml representation of the table""" | ||
pass | ||
|
||
|
||
def pandas_df_to_xml(df: pd.DataFrame) -> str: | ||
"""Converts Pandas df to a simplified xml representation digestible by LLMs | ||
Args: | ||
df (pd.DataFrame): Pandas df | ||
Returns: | ||
str: xml string | ||
""" | ||
|
||
def func(row): | ||
xml = ["<row>"] | ||
for field in row.index: | ||
xml.append(' <col name="{0}">{1}</col>'.format(field, row[field])) | ||
xml.append("</row>") | ||
return "\n".join(xml) | ||
|
||
items = df.apply(func, axis=1) | ||
return "\n".join(items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters