Skip to content

Commit

Permalink
Fix extracted table output format to better json (#4969)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbirk authored Sep 27, 2024
1 parent 90fc511 commit 0b9b98e
Showing 1 changed file with 12 additions and 11 deletions.
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

0 comments on commit 0b9b98e

Please sign in to comment.