CodeStyle

This commit is contained in:
deiflaender 2020-07-22 14:14:10 +02:00
parent 6a9df397eb
commit e7ea12a1b0

View File

@ -36,8 +36,10 @@ import lombok.extern.slf4j.Slf4j;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class AnnotationHighlightService { public class AnnotationHighlightService {
private final DictionaryService dictionaryService; private final DictionaryService dictionaryService;
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction) throws IOException { public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction) throws IOException {
for (int page = 1; page <= document.getNumberOfPages(); page++) { for (int page = 1; page <= document.getNumberOfPages(); page++) {
@ -98,18 +100,29 @@ public class AnnotationHighlightService {
posXEnd = textPositions.getTextPositions().get(0).getYDirAdj() + 2; posXEnd = textPositions.getTextPositions().get(0).getYDirAdj() + 2;
posXInit = textPositions.getTextPositions().get(0).getYDirAdj() - height; posXInit = textPositions.getTextPositions().get(0).getYDirAdj() - height;
posYInit = textPositions.getTextPositions().get(0).getXDirAdj(); posYInit = textPositions.getTextPositions().get(0).getXDirAdj();
posYEnd = textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getXDirAdj() - height + 4; posYEnd = textPositions.getTextPositions()
.get(textPositions.getTextPositions().size() - 1)
.getXDirAdj() - height + 4;
} else { } else {
posXInit = textPositions.getTextPositions().get(0).getXDirAdj(); posXInit = textPositions.getTextPositions().get(0).getXDirAdj();
posXEnd = textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getXDirAdj() + textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getWidth() + 1; posXEnd = textPositions.getTextPositions()
posYInit = textPositions.getTextPositions().get(0).getPageHeight() - textPositions.getTextPositions().get(0).getYDirAdj() - 2; .get(textPositions.getTextPositions().size() - 1)
posYEnd = textPositions.getTextPositions().get(0).getPageHeight() - textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getYDirAdj() + 2; .getXDirAdj() + textPositions.getTextPositions()
.get(textPositions.getTextPositions().size() - 1)
.getWidth() + 1;
posYInit = textPositions.getTextPositions()
.get(0)
.getPageHeight() - textPositions.getTextPositions().get(0).getYDirAdj() - 2;
posYEnd = textPositions.getTextPositions()
.get(0)
.getPageHeight() - textPositions.getTextPositions()
.get(textPositions.getTextPositions().size() - 1)
.getYDirAdj() + 2;
} }
Rectangle textHighlightRectangle = new Rectangle(new Point(posXInit, posYInit), posXEnd - posXInit, posYEnd - posYInit + height, page); Rectangle textHighlightRectangle = new Rectangle(new Point(posXInit, posYInit), posXEnd - posXInit, posYEnd - posYInit + height, page);
List<PDAnnotation> annotations = pdPage.getAnnotations(); List<PDAnnotation> annotations = pdPage.getAnnotations();
PDAnnotationTextMarkup highlight = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT); PDAnnotationTextMarkup highlight = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
highlight.constructAppearances(); highlight.constructAppearances();
@ -124,7 +137,8 @@ public class AnnotationHighlightService {
if (!flatRedaction && !isHint(entity)) { if (!flatRedaction && !isHint(entity)) {
highlight.setAnnotationName(entityPositionSequence.getId().toString()); highlight.setAnnotationName(entityPositionSequence.getId().toString());
highlight.setTitlePopup(entityPositionSequence.getId().toString()); highlight.setTitlePopup(entityPositionSequence.getId().toString());
highlight.setContents("\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\n" + "In Section : \"" + entity.getHeadline() + "\""); highlight.setContents("\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\n" + "In Section : \"" + entity
.getHeadline() + "\"");
} }
highlight.setQuadPoints(toQuadPoints(textHighlightRectangle)); highlight.setQuadPoints(toQuadPoints(textHighlightRectangle));
@ -162,31 +176,32 @@ 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[]{ return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), rectangle.getTopLeft()
rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), .getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(), rectangle.getTopLeft()
rectangle.getTopLeft().getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), .getY() + rectangle.getHeight(), rectangle.getTopLeft()
rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY() + rectangle.getHeight(), .getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()};
rectangle.getTopLeft().getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()};
} }
private boolean isRedactionType(Entity entity) { private boolean isRedactionType(Entity entity) {
if (!entity.isRedaction()) { if (!entity.isRedaction()) {
return false; return false;
} }
if(isHint(entity)){ if (isHint(entity)) {
return false; return false;
} }
return true; return true;
} }
private float[] getColor(Entity entity) { private float[] getColor(Entity entity) {
if (!entity.isRedaction() && !isHint(entity)) { if (!entity.isRedaction() && !isHint(entity)) {
return new float[]{0.627f, 0.627f, 0.627f}; return new float[]{0.627f, 0.627f, 0.627f};
} }
if(!dictionaryService.getEntryColors().containsKey(entity.getType())){ if (!dictionaryService.getEntryColors().containsKey(entity.getType())) {
return dictionaryService.getEntryColors().get("default"); return dictionaryService.getEntryColors().get("default");
} }
@ -194,14 +209,16 @@ public class AnnotationHighlightService {
} }
private boolean isHint(Entity entity){ private boolean isHint(Entity entity) {
// TODO in RED-161. // TODO in RED-161.
if(entity.getType().equalsIgnoreCase("vertebrate") || entity.getType().equalsIgnoreCase("no_redaction_indicator")){ if (entity.getType().equalsIgnoreCase("vertebrate") || entity.getType()
.equalsIgnoreCase("no_redaction_indicator")) {
return true; return true;
} }
return false; return false;
} }
private void visualizeTextBlock(TextBlock textBlock, PDPageContentStream contentStream) throws IOException { private void visualizeTextBlock(TextBlock textBlock, PDPageContentStream contentStream) throws IOException {
contentStream.setStrokingColor(Color.LIGHT_GRAY); contentStream.setStrokingColor(Color.LIGHT_GRAY);
@ -226,13 +243,15 @@ public class AnnotationHighlightService {
private void visualizeTable(Table table, PDPageContentStream contentStream) throws IOException { private void visualizeTable(Table table, PDPageContentStream contentStream) throws IOException {
for (List<Cell> row : table.getRows()) { for (List<Cell> row : table.getRows()) {
for (Cell cell : row) { for (Cell cell : row) {
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.getHeight()); contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(), (float) cell
.getHeight());
contentStream.stroke(); contentStream.stroke();
// contentStream.setStrokingColor(Color.GREEN); // contentStream.setStrokingColor(Color.GREEN);
@ -257,4 +276,5 @@ public class AnnotationHighlightService {
contentStream.endText(); contentStream.endText();
} }
} }
} }