Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extracted table output format to better json #4969

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ static class ExtractPDFResponse {
List<JsonNode> equations = new ArrayList<>();
List<JsonNode> tables = new ArrayList<>();
ArrayNode variableAttributes;
JsonNode gollmCard;
boolean partialFailure = true;
}

Expand Down Expand Up @@ -318,13 +317,6 @@ public DocumentAsset applyExtractPDFResponse(
document.getMetadata().put("attributes", extractionResponse.variableAttributes);
}

if (extractionResponse.gollmCard != null) {
if (document.getMetadata() == null) {
document.setMetadata(new HashMap<>());
}
document.getMetadata().put("gollmCard", extractionResponse.gollmCard);
}

if (extractionResponse.equations != null) {
if (document.getMetadata() == null) {
document.setMetadata(new HashMap<>());
Expand All @@ -339,8 +331,6 @@ public DocumentAsset applyExtractPDFResponse(
document.getMetadata().put("tables", objectMapper.valueToTree(extractionResponse.tables));
}

log.info("Added extraction to document: {}", documentId);

return documentService.updateAsset(document, projectId, hasWritePermission).orElseThrow();
}

Expand Down Expand Up @@ -909,7 +899,18 @@ public Future<TableExtraction> extractTablesFromPDF(
final TableExtraction extraction = new TableExtraction();

for (final String key : keys) {
extraction.tables.add(output.getResponse().get(key));
final JsonNode page = output.getResponse().get(key);
if (page.isArray()) {
final ArrayNode pageOfTables = objectMapper.createArrayNode();
for (final JsonNode table : page) {
JsonNode t = table;
if (table.isTextual()) {
t = objectMapper.readTree(table.asText());
}
pageOfTables.add(t);
}
extraction.tables.add(pageOfTables);
}
}

return extraction;
Expand Down
Loading