Skip to content

Commit

Permalink
Fix tables / equations (#5025)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbirk authored Oct 3, 2024
1 parent 8d586f8 commit 230a8ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
public class ExtractedDocumentPage implements Serializable {

@Serial
private static final long serialVersionUID = 7781295818378531195L;
private static final long serialVersionUID = 1289317238497123L;

Integer pageNumber;

String text;
List<JsonNode> tables = new ArrayList<>();

List<JsonNode> equations = new ArrayList<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,30 @@ public DocumentAsset applyExtractPDFResponse(
document.getMetadata().put("attributes", extractionResponse.variableAttributes);
}

pageNum = 0;
if (extractionResponse.equations != null) {
document.getMetadata().put("equations", objectMapper.valueToTree(extractionResponse.equations));

document.getExtractions().get(pageNum).setEquations(extractionResponse.equations);
pageNum++;
pageNum = 0;
for (final JsonNode page : extractionResponse.equations) {
final ArrayNode equationsForPage = (ArrayNode) page;
for (final JsonNode equation : equationsForPage) {
document.getExtractions().get(pageNum).getEquations().add(equation);
}
pageNum++;
}
}

pageNum = 0;
if (extractionResponse.tables != null) {
document.getMetadata().put("tables", objectMapper.valueToTree(extractionResponse.tables));

document.getExtractions().get(pageNum).setEquations(extractionResponse.tables);
pageNum++;
pageNum = 0;
for (final JsonNode page : extractionResponse.tables) {
final ArrayNode tablesForPage = (ArrayNode) page;
for (final JsonNode table : tablesForPage) {
document.getExtractions().get(pageNum).getTables().add(table);
}
pageNum++;
}
}

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

0 comments on commit 230a8ac

Please sign in to comment.