Commit ·
6b5c8d2
1
Parent(s): f9f8af8
Add source-lineage export helper
Browse files- src/output_writer.py +17 -1
src/output_writer.py
CHANGED
|
@@ -21,6 +21,22 @@ def chunks_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
|
| 21 |
return pd.DataFrame([chunk.model_dump() for chunk in report.chunks])
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def metadata_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
| 25 |
"""Convert metadata into a dataframe."""
|
| 26 |
return pd.DataFrame([report.metadata.model_dump()])
|
|
@@ -28,7 +44,7 @@ def metadata_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
|
| 28 |
|
| 29 |
def summary_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
| 30 |
"""Convert summary fields into a simple dataframe."""
|
| 31 |
-
summary = report.summary.model_dump()
|
| 32 |
|
| 33 |
rows = []
|
| 34 |
for field, value in summary.items():
|
|
|
|
| 21 |
return pd.DataFrame([chunk.model_dump() for chunk in report.chunks])
|
| 22 |
|
| 23 |
|
| 24 |
+
def findings_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
| 25 |
+
"""Convert source-linked structured findings into a dataframe."""
|
| 26 |
+
rows = []
|
| 27 |
+
for finding in report.summary.findings:
|
| 28 |
+
rows.append(
|
| 29 |
+
{
|
| 30 |
+
"finding_id": finding.finding_id,
|
| 31 |
+
"category": finding.category.replace("_", " ").title(),
|
| 32 |
+
"finding": finding.text,
|
| 33 |
+
"page": finding.page_number,
|
| 34 |
+
"chunk": finding.chunk_id,
|
| 35 |
+
}
|
| 36 |
+
)
|
| 37 |
+
return pd.DataFrame(rows)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def metadata_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
| 41 |
"""Convert metadata into a dataframe."""
|
| 42 |
return pd.DataFrame([report.metadata.model_dump()])
|
|
|
|
| 44 |
|
| 45 |
def summary_to_dataframe(report: DocumentIntelligenceReport) -> pd.DataFrame:
|
| 46 |
"""Convert summary fields into a simple dataframe."""
|
| 47 |
+
summary = report.summary.model_dump(exclude={"findings"})
|
| 48 |
|
| 49 |
rows = []
|
| 50 |
for field, value in summary.items():
|