Pull request #10: Do not return redacted=true for vertebrates in RedactionLog, return isHint=true and redacted=false

Merge in RED/redaction-service from RedactionLog1 to master

* commit 'e7ea12a1b03f7f79e0f4fa12671f91ee326eef73':
  CodeStyle
  Do not return redacted=true for vertebrates in RedactionLog, return isHint=true and redacted=false
This commit is contained in:
Dominique Eiflaender 2020-07-22 14:15:56 +02:00
commit 94827a417f
4 changed files with 50 additions and 36 deletions

View File

@ -13,6 +13,7 @@ public class RedactionLogEntry {
private String value; private String value;
private String reason; private String reason;
private boolean redacted; private boolean redacted;
private boolean isHint;
private String section; private String section;
private float[] color; private float[] color;
private List<Rectangle> positions = new ArrayList<>(); private List<Rectangle> positions = new ArrayList<>();

View File

@ -49,15 +49,6 @@ public class Section {
}); });
} }
public void highlightAll(String type){
entities.forEach(entity -> {
if(entity.getType().equals(type)){
entity.setRedaction(true);
}
});
}
public void redactLineAfter(String start, String asType, int ruleNumber, String reason){ public void redactLineAfter(String start, String asType, int ruleNumber, String reason){
String value = StringUtils.substringBetween(text, start, "\n"); String value = StringUtils.substringBetween(text, start, "\n");

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();
@ -121,10 +134,11 @@ public class AnnotationHighlightService {
annotationPosition.setUpperRightY(posYEnd + height); annotationPosition.setUpperRightY(posYEnd + height);
highlight.setRectangle(annotationPosition); highlight.setRectangle(annotationPosition);
if (!flatRedaction) { 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));
@ -150,6 +164,7 @@ public class AnnotationHighlightService {
redactionLogEntry.setType(entity.getType()); redactionLogEntry.setType(entity.getType());
redactionLogEntry.setRedacted(entity.isRedaction()); redactionLogEntry.setRedacted(entity.isRedaction());
redactionLogEntry.setSection(entity.getHeadline()); redactionLogEntry.setSection(entity.getHeadline());
redactionLogEntry.setHint(isHint(entity));
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry); classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
} }
@ -161,37 +176,49 @@ 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(entity.getType().equalsIgnoreCase("VERTEBRATE") || entity.getType().equalsIgnoreCase("NO_REDACTION_INDICATOR") ){ if (isHint(entity)) {
// TODO in RED-161. return false;
return true;
} }
return dictionaryService.getDictionary().keySet().contains(entity.getType()); return true;
} }
private float[] getColor(Entity entity) { private float[] getColor(Entity entity) {
if (!entity.isRedaction()) {
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");
} }
return dictionaryService.getEntryColors().get(entity.getType()); return dictionaryService.getEntryColors().get(entity.getType());
} }
private boolean isHint(Entity entity) {
// TODO in RED-161.
if (entity.getType().equalsIgnoreCase("vertebrate") || entity.getType()
.equalsIgnoreCase("no_redaction_indicator")) {
return true;
}
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);
@ -216,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);
@ -247,4 +276,5 @@ public class AnnotationHighlightService {
contentStream.endText(); contentStream.endText();
} }
} }
} }

View File

@ -4,14 +4,6 @@ import com.iqser.red.service.redaction.v1.server.redaction.model.Section
global Section section global Section section
rule "0: Highlight Indicators"
when
eval(section.getEntities().isEmpty()==false);
then
section.highlightAll("vertebrate");
section.highlightAll("no_redaction_indicator");
end
rule "1: Redacted because Section contains Vertebrate" rule "1: Redacted because Section contains Vertebrate"
when when