Merge rectangles for single annotation/redaction log entry
This commit is contained in:
parent
03274ba1ab
commit
5448153096
@ -27,9 +27,7 @@ import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
|||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class EntityRedactionService {
|
public class EntityRedactionService {
|
||||||
|
|||||||
@ -35,9 +35,7 @@ import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
|||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AnnotationHighlightService {
|
public class AnnotationHighlightService {
|
||||||
@ -45,7 +43,8 @@ public class AnnotationHighlightService {
|
|||||||
private final DictionaryService dictionaryService;
|
private final DictionaryService dictionaryService;
|
||||||
|
|
||||||
|
|
||||||
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions) throws IOException {
|
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction,
|
||||||
|
ManualRedactions manualRedactions) throws IOException {
|
||||||
|
|
||||||
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
||||||
|
|
||||||
@ -83,7 +82,8 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions, int page) throws IOException {
|
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction,
|
||||||
|
ManualRedactions manualRedactions, int page) throws IOException {
|
||||||
|
|
||||||
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
||||||
|
|
||||||
@ -107,11 +107,22 @@ public class AnnotationHighlightService {
|
|||||||
redactionLogEntry.setManual(true);
|
redactionLogEntry.setManual(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TextPositionSequence textPositions : entityPositionSequence.getSequences()) {
|
if (CollectionUtils.isNotEmpty(entityPositionSequence.getSequences())) {
|
||||||
|
Rectangle rectangle = new Rectangle();
|
||||||
Rectangle rectangle = textPositions.getRectangle();
|
rectangle.setTopLeft(entityPositionSequence.getSequences().get(0).getRectangle().getTopLeft());
|
||||||
|
rectangle.setHeight((float) entityPositionSequence.getSequences()
|
||||||
|
.stream()
|
||||||
|
.mapToDouble(TextPositionSequence::getHeight)
|
||||||
|
.max()
|
||||||
|
.getAsDouble());
|
||||||
|
rectangle.setWidth((float) entityPositionSequence.getSequences()
|
||||||
|
.stream()
|
||||||
|
.mapToDouble(TextPositionSequence::getWidth)
|
||||||
|
.sum());
|
||||||
|
rectangle.setPage(page);
|
||||||
redactionLogEntry.getPositions().add(rectangle);
|
redactionLogEntry.getPositions().add(rectangle);
|
||||||
annotations.add(createAnnotation(rectangle, entityPositionSequence.getId(), createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
|
annotations.add(createAnnotation(rectangle, entityPositionSequence.getId(),
|
||||||
|
createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
|
||||||
}
|
}
|
||||||
redactionLogEntry.setId(entityPositionSequence.getId());
|
redactionLogEntry.setId(entityPositionSequence.getId());
|
||||||
}
|
}
|
||||||
@ -120,7 +131,8 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addManualAnnotations(PDPage pdPage, Document classifiedDoc, ManualRedactions manualRedactions, int page) throws IOException {
|
private void addManualAnnotations(PDPage pdPage, Document classifiedDoc, ManualRedactions manualRedactions,
|
||||||
|
int page) throws IOException {
|
||||||
|
|
||||||
if (manualRedactions == null) {
|
if (manualRedactions == null) {
|
||||||
return;
|
return;
|
||||||
@ -143,7 +155,8 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
foundOnPage = true;
|
foundOnPage = true;
|
||||||
|
|
||||||
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id,
|
||||||
|
createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
||||||
.getType()), true);
|
.getType()), true);
|
||||||
annotations.add(highlight);
|
annotations.add(highlight);
|
||||||
|
|
||||||
@ -188,7 +201,8 @@ public class AnnotationHighlightService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PDAnnotationTextMarkup createAnnotation(Rectangle rectangle, String id, String content, float[] color, boolean popup) {
|
private PDAnnotationTextMarkup createAnnotation(Rectangle rectangle, String id, String content, float[] color,
|
||||||
|
boolean popup) {
|
||||||
|
|
||||||
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
|
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
|
||||||
annotation.constructAppearances();
|
annotation.constructAppearances();
|
||||||
@ -206,25 +220,15 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
private String createAnnotationContent(Entity entity) {
|
private String createAnnotationContent(Entity entity) {
|
||||||
|
|
||||||
return new StringBuilder().append("\nRule ")
|
return "\nRule " + entity.getMatchedRule() + " matched" + "\n\n" + entity.getRedactionReason() + "\n\nIn " +
|
||||||
.append(entity.getMatchedRule())
|
"Section : \"" + entity
|
||||||
.append(" matched")
|
.getHeadline() + "\"";
|
||||||
.append("\n\n")
|
|
||||||
.append(entity.getRedactionReason())
|
|
||||||
.append("\n\nIn Section : \"")
|
|
||||||
.append(entity.getHeadline())
|
|
||||||
.append("\"")
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String createAnnotationContent(ManualRedactionEntry entry) {
|
private String createAnnotationContent(ManualRedactionEntry entry) {
|
||||||
|
|
||||||
return new StringBuilder().append("\nManual Redaction")
|
return "\nManual Redaction" + "\n\nIn Section : \"" + entry.getSection() + "\"";
|
||||||
.append("\n\nIn Section : \"")
|
|
||||||
.append(entry.getSection())
|
|
||||||
.append("\"")
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +248,8 @@ public class AnnotationHighlightService {
|
|||||||
// 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(), rectangle.getTopLeft()
|
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(),
|
||||||
|
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()};
|
||||||
}
|
}
|
||||||
@ -255,10 +260,7 @@ public class AnnotationHighlightService {
|
|||||||
if (!entity.isRedaction()) {
|
if (!entity.isRedaction()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isHint(entity)) {
|
return !isHint(entity);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -286,20 +288,19 @@ public class AnnotationHighlightService {
|
|||||||
private boolean isHint(Entity entity) {
|
private boolean isHint(Entity entity) {
|
||||||
|
|
||||||
List<String> hintTypes = dictionaryService.getHintTypes();
|
List<String> hintTypes = dictionaryService.getHintTypes();
|
||||||
if (CollectionUtils.isNotEmpty(hintTypes) && hintTypes.contains(entity.getType())) {
|
return CollectionUtils.isNotEmpty(hintTypes) && hintTypes.contains(entity.getType());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void drawSectionFrames(PDDocument document, Document classifiedDoc, boolean flatRedaction, PDPage pdPage, int page) throws IOException {
|
private void drawSectionFrames(PDDocument document, Document classifiedDoc, boolean flatRedaction, PDPage pdPage,
|
||||||
|
int page) throws IOException {
|
||||||
|
|
||||||
if (flatRedaction) {
|
if (flatRedaction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage, PDPageContentStream.AppendMode.APPEND, true);
|
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage,
|
||||||
|
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++) {
|
||||||
@ -348,7 +349,8 @@ 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(), (float) cell
|
contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(),
|
||||||
|
(float) cell
|
||||||
.getHeight());
|
.getHeight());
|
||||||
contentStream.stroke();
|
contentStream.stroke();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user