RED-373: Use a single multiline annotation instead of seperate annotations per line for one Entity
This commit is contained in:
parent
99bde2956f
commit
ce22121802
@ -46,8 +46,7 @@ public class AnnotationHighlightService {
|
|||||||
private final DictionaryService dictionaryService;
|
private final DictionaryService dictionaryService;
|
||||||
|
|
||||||
|
|
||||||
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction,
|
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions) throws IOException {
|
||||||
ManualRedactions manualRedactions) throws IOException {
|
|
||||||
|
|
||||||
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
||||||
|
|
||||||
@ -85,8 +84,7 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction,
|
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions, int page) throws IOException {
|
||||||
ManualRedactions manualRedactions, int page) throws IOException {
|
|
||||||
|
|
||||||
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
||||||
|
|
||||||
@ -111,22 +109,24 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(entityPositionSequence.getSequences())) {
|
if (CollectionUtils.isNotEmpty(entityPositionSequence.getSequences())) {
|
||||||
for (Rectangle rectangle : getRectanglesPerLine(entityPositionSequence.getSequences()
|
List<Rectangle> rectanglesPerline = getRectanglesPerLine(entityPositionSequence.getSequences()
|
||||||
.stream()
|
.stream()
|
||||||
.flatMap(seq -> seq.getTextPositions().stream())
|
.flatMap(seq -> seq.getTextPositions().stream())
|
||||||
.collect(Collectors.toList()), page)) {
|
.collect(Collectors.toList()), page);
|
||||||
redactionLogEntry.getPositions().add(rectangle);
|
|
||||||
annotations.add(createAnnotation(rectangle, entityPositionSequence.getId(),
|
redactionLogEntry.getPositions().addAll(rectanglesPerline);
|
||||||
createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
|
annotations.add(createAnnotation(rectanglesPerline, entityPositionSequence.getId(), createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
redactionLogEntry.setId(entityPositionSequence.getId());
|
|
||||||
}
|
redactionLogEntry.setId(entityPositionSequence.getId());
|
||||||
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
|
|
||||||
}
|
}
|
||||||
|
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Rectangle> getRectanglesPerLine(List<TextPosition> textPositions, int page) {
|
private List<Rectangle> getRectanglesPerLine(List<TextPosition> textPositions, int page) {
|
||||||
|
|
||||||
List<Rectangle> rectangles = new ArrayList<>();
|
List<Rectangle> rectangles = new ArrayList<>();
|
||||||
@ -152,8 +152,7 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addManualAnnotations(PDPage pdPage, Document classifiedDoc, ManualRedactions manualRedactions,
|
private void addManualAnnotations(PDPage pdPage, Document classifiedDoc, ManualRedactions manualRedactions, int page) throws IOException {
|
||||||
int page) throws IOException {
|
|
||||||
|
|
||||||
if (manualRedactions == null) {
|
if (manualRedactions == null) {
|
||||||
return;
|
return;
|
||||||
@ -176,8 +175,8 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
foundOnPage = true;
|
foundOnPage = true;
|
||||||
|
|
||||||
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id,
|
PDAnnotationTextMarkup highlight = createAnnotation(List.of(rectangle), id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
||||||
createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry.getType()), true);
|
.getType()), true);
|
||||||
annotations.add(highlight);
|
annotations.add(highlight);
|
||||||
|
|
||||||
redactionLogEntry.getPositions().add(rectangle);
|
redactionLogEntry.getPositions().add(rectangle);
|
||||||
@ -221,13 +220,12 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PDAnnotationTextMarkup createAnnotation(Rectangle rectangle, String id, String content, float[] color,
|
private PDAnnotationTextMarkup createAnnotation(List<Rectangle> rectangles, String id, String content, float[] color, boolean popup) {
|
||||||
boolean popup) {
|
|
||||||
|
|
||||||
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
|
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
|
||||||
annotation.constructAppearances();
|
annotation.constructAppearances();
|
||||||
annotation.setRectangle(toPDRectangle(rectangle));
|
annotation.setRectangle(toPDRectangle(rectangles.get(0)));
|
||||||
annotation.setQuadPoints(toQuadPoints(rectangle));
|
annotation.setQuadPoints(toQuadPoints(rectangles));
|
||||||
if (popup) {
|
if (popup) {
|
||||||
annotation.setAnnotationName(id);
|
annotation.setAnnotationName(id);
|
||||||
annotation.setTitlePopup(id);
|
annotation.setTitlePopup(id);
|
||||||
@ -240,8 +238,7 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
private String createAnnotationContent(Entity entity) {
|
private String createAnnotationContent(Entity entity) {
|
||||||
|
|
||||||
return "\nRule " + entity.getMatchedRule() + " matched" + "\n\n" + entity.getRedactionReason() + "\n\nIn " +
|
return "\nRule " + entity.getMatchedRule() + " matched" + "\n\n" + entity.getRedactionReason() + "\n\nIn " + "Section : \"" + entity
|
||||||
"Section : \"" + entity
|
|
||||||
.getHeadline() + "\"";
|
.getHeadline() + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,13 +260,29 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private float[] toQuadPoints(Rectangle rectangle) {
|
private float[] toQuadPoints(List<Rectangle> rectangles) {
|
||||||
|
|
||||||
|
|
||||||
|
float[] quadPoints = new float[rectangles.size() * 8];
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (Rectangle rectangle : rectangles) {
|
||||||
|
float[] quadPoint = toQuadPoint(rectangle);
|
||||||
|
for (int j = 0; j <= 7; j++) {
|
||||||
|
quadPoints[i + j] = quadPoint[j];
|
||||||
|
}
|
||||||
|
i += 8;
|
||||||
|
}
|
||||||
|
return quadPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private float[] toQuadPoint(Rectangle rectangle) {
|
||||||
|
|
||||||
// quadPoints is array of x,y coordinates in Z-like order (top-left, top-right, bottom-left,bottom-right)
|
// quadPoints is array of x,y coordinates in Z-like order (top-left, top-right, bottom-left,bottom-right)
|
||||||
// of the area to be highlighted
|
// of the area to be highlighted
|
||||||
return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), rectangle.getTopLeft()
|
return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), rectangle.getTopLeft()
|
||||||
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(),
|
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(), rectangle.getTopLeft()
|
||||||
rectangle.getTopLeft()
|
|
||||||
.getY() + rectangle.getHeight(), rectangle.getTopLeft()
|
.getY() + rectangle.getHeight(), rectangle.getTopLeft()
|
||||||
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()};
|
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()};
|
||||||
}
|
}
|
||||||
@ -312,15 +325,13 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void drawSectionFrames(PDDocument document, Document classifiedDoc, boolean flatRedaction, PDPage pdPage,
|
private void drawSectionFrames(PDDocument document, Document classifiedDoc, boolean flatRedaction, PDPage pdPage, int page) throws IOException {
|
||||||
int page) throws IOException {
|
|
||||||
|
|
||||||
if (flatRedaction) {
|
if (flatRedaction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage,
|
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage, PDPageContentStream.AppendMode.APPEND, true);
|
||||||
PDPageContentStream.AppendMode.APPEND, true);
|
|
||||||
for (Paragraph paragraph : classifiedDoc.getParagraphs()) {
|
for (Paragraph paragraph : classifiedDoc.getParagraphs()) {
|
||||||
|
|
||||||
for (int i = 0; i <= paragraph.getPageBlocks().size() - 1; i++) {
|
for (int i = 0; i <= paragraph.getPageBlocks().size() - 1; i++) {
|
||||||
@ -369,8 +380,7 @@ public class AnnotationHighlightService {
|
|||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
contentStream.setLineWidth(0.5f);
|
contentStream.setLineWidth(0.5f);
|
||||||
contentStream.setStrokingColor(Color.CYAN);
|
contentStream.setStrokingColor(Color.CYAN);
|
||||||
contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(),
|
contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(), (float) cell
|
||||||
(float) cell
|
|
||||||
.getHeight());
|
.getHeight());
|
||||||
contentStream.stroke();
|
contentStream.stroke();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user