Made rules for table more stabil and flexible
This commit is contained in:
parent
d026f4e1db
commit
559c421542
@ -35,21 +35,11 @@ public class Section {
|
||||
private Map<String, TextBlock> tabularData;
|
||||
|
||||
|
||||
public boolean isVertebrateStudy() {
|
||||
return tabularData != null
|
||||
&& (tabularData.containsKey("Vertebrate study Y/N")
|
||||
&& tabularData.get("Vertebrate study Y/N").getText().equals("Y")
|
||||
|| tabularData.containsKey("Verte brate study Y/N")
|
||||
&& tabularData.get("Verte brate study Y/N").getText().equals("Y"));
|
||||
}
|
||||
public boolean rowEquals(String headerName, String value){
|
||||
String cleanHeaderName = headerName.replaceAll("\n", "")
|
||||
.replaceAll(" ", "");
|
||||
|
||||
|
||||
public boolean isNotVertebrateStudy() {
|
||||
return tabularData != null
|
||||
&& (tabularData.containsKey("Vertebrate study Y/N")
|
||||
&& tabularData.get("Vertebrate study Y/N").getText().equals("N")
|
||||
|| tabularData.containsKey("Verte brate study Y/N")
|
||||
&& tabularData.get("Verte brate study Y/N").getText().equals("N"));
|
||||
return tabularData != null && tabularData.containsKey(cleanHeaderName) && tabularData.get(cleanHeaderName).getText().equals(value);
|
||||
}
|
||||
|
||||
|
||||
@ -182,7 +172,10 @@ public class Section {
|
||||
|
||||
public void highlightCell(String cellHeader, int ruleNumber, String type) {
|
||||
|
||||
TextBlock value = tabularData.get(cellHeader);
|
||||
String cleanHeaderName = cellHeader.replaceAll("\n", "")
|
||||
.replaceAll(" ", "");
|
||||
|
||||
TextBlock value = tabularData.get(cleanHeaderName);
|
||||
if (value == null) {
|
||||
log.warn("Could not find any data for {}.", cellHeader);
|
||||
} else {
|
||||
@ -196,4 +189,4 @@ public class Section {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,9 +60,12 @@ public class EntityRedactionService {
|
||||
}
|
||||
addSectionToManualRedactions(cell.getTextBlocks(), manualRedactions, table.getHeadline(), sectionNumber);
|
||||
cell.getHeaderCells().forEach(headerCell -> {
|
||||
String headerName = headerCell.getTextBlocks().get(0).getText()
|
||||
.replaceAll("\n", " ")
|
||||
.replaceAll(" ", " ");
|
||||
|
||||
StringBuilder headerBuilder = new StringBuilder();
|
||||
headerCell.getTextBlocks().forEach(textBlock -> headerBuilder.append(textBlock.getText()));
|
||||
String headerName = headerBuilder.toString()
|
||||
.replaceAll("\n", "")
|
||||
.replaceAll(" ", "");
|
||||
tabularData.put(headerName, cell.getTextBlocks().get(0));
|
||||
});
|
||||
for (TextBlock textBlock : cell.getTextBlocks()) {
|
||||
|
||||
@ -228,7 +228,7 @@ public class EntityRedactionServiceTest {
|
||||
"global Section section\n" +
|
||||
"rule \"9: Redact Authors and Addresses in Reference Table, if it is a Vertebrate study\"\n" +
|
||||
" when\n" +
|
||||
" Section(isVertebrateStudy())\n" +
|
||||
" Section(rowEquals(\"Vertebrate study Y/N\", \"Y\"))\n" +
|
||||
" then\n" +
|
||||
" section.redact(\"name\", 9, \"Redacted because row is a vertebrate study\");\n" +
|
||||
" section.redact(\"address\", 9, \"Redacted because rows is a vertebrate study\");\n" +
|
||||
|
||||
@ -93,12 +93,11 @@ rule "7: Redact contact information, if Producer is found"
|
||||
|
||||
rule "8: Not redacted because Vertebrate Study = N"
|
||||
when
|
||||
Section(isNotVertebrateStudy())
|
||||
Section(rowEquals("Vertebrate study Y/N", "N"))
|
||||
then
|
||||
section.redactNot("name", 8, "Not redacted because row is not a vertebrate study");
|
||||
section.redactNot("address", 8, "Not redacted because row is not a vertebrate study");
|
||||
section.highlightCell("Vertebrate study Y/N", 8, "hint_only");
|
||||
section.highlightCell("Verte brate study Y/N", 8, "hint_only");
|
||||
end
|
||||
|
||||
|
||||
@ -110,12 +109,12 @@ rule "9: Redact if must redact entry is found"
|
||||
section.redact("address", 9, "must_redact entry was found.");
|
||||
end
|
||||
|
||||
|
||||
rule "10: Redact Authors and Addresses in Reference Table, if it is a Vertebrate study"
|
||||
when
|
||||
Section(isVertebrateStudy())
|
||||
Section(rowEquals("Vertebrate study Y/N", "Y"))
|
||||
then
|
||||
section.redact("name", 10, "Redacted because row is a vertebrate study");
|
||||
section.redact("address", 10, "Redacted because row is a vertebrate study");
|
||||
section.highlightCell("Vertebrate study Y/N", 10, "must_redact");
|
||||
section.highlightCell("Verte brate study Y/N", 10, "must_redact");
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user