Avoid ConcurrentModificationException

This commit is contained in:
deiflaender 2020-12-09 13:14:04 +01:00
parent 3f69030b03
commit 320bc6f70c
4 changed files with 41 additions and 9 deletions

View File

@ -0,0 +1,13 @@
package com.iqser.red.service.redaction.v1.server.redaction.model;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class RowSectionPair {
private Section section;
private SearchableText searchableRow;
}

View File

@ -307,12 +307,17 @@ public class Section {
while (matcher.find()) { while (matcher.find()) {
String match = matcher.group().trim(); String match = matcher.group().trim();
if (match.length() >= 3) { if (match.length() >= 3 && !dictionaryService.getDictionary(type)
if(!dictionaryService.getDictionary(type).getEntries().contains(match) && !dictionaryService.getDictionary(RECOMMENDATION_PREFIX + type).getEntries().contains(match)) { .getEntries()
.contains(match) && !dictionaryService.getDictionary(RECOMMENDATION_PREFIX + type)
.getEntries()
.contains(match)) {
dictionaryService.addToLocalDictionary(RECOMMENDATION_PREFIX + type, match); dictionaryService.addToLocalDictionary(RECOMMENDATION_PREFIX + type, match);
}
String lastname = match.split(" ")[0]; String lastname = match.split(" ")[0];
if(!dictionaryService.getDictionary(type).getEntries().contains(lastname) && !dictionaryService.getDictionary(RECOMMENDATION_PREFIX + type).getEntries().contains(lastname)) { if (!dictionaryService.getDictionary(type).getEntries().contains(lastname) && !dictionaryService
.getDictionary(RECOMMENDATION_PREFIX + type)
.getEntries()
.contains(lastname)) {
dictionaryService.addToLocalDictionary(RECOMMENDATION_PREFIX + type, lastname); dictionaryService.addToLocalDictionary(RECOMMENDATION_PREFIX + type, lastname);
} }
} }

View File

@ -24,6 +24,7 @@ import com.iqser.red.service.redaction.v1.server.redaction.model.CellValue;
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryModel; import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryModel;
import com.iqser.red.service.redaction.v1.server.redaction.model.Entity; import com.iqser.red.service.redaction.v1.server.redaction.model.Entity;
import com.iqser.red.service.redaction.v1.server.redaction.model.EntityPositionSequence; import com.iqser.red.service.redaction.v1.server.redaction.model.EntityPositionSequence;
import com.iqser.red.service.redaction.v1.server.redaction.model.RowSectionPair;
import com.iqser.red.service.redaction.v1.server.redaction.model.SearchableText; import com.iqser.red.service.redaction.v1.server.redaction.model.SearchableText;
import com.iqser.red.service.redaction.v1.server.redaction.model.Section; import com.iqser.red.service.redaction.v1.server.redaction.model.Section;
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell; import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
@ -96,6 +97,7 @@ public class EntityRedactionService {
List<Table> tables = paragraph.getTables(); List<Table> tables = paragraph.getTables();
List<RowSectionPair> tableRowSections = new ArrayList<>();
for (Table table : tables) { for (Table table : tables) {
boolean singleCellTable = table.getRowCount() == 1 && table.getColCount() == 1; boolean singleCellTable = table.getRowCount() == 1 && table.getColCount() == 1;
for (List<Cell> row : table.getRows()) { for (List<Cell> row : table.getRows()) {
@ -124,7 +126,7 @@ public class EntityRedactionService {
} }
Set<Entity> rowEntities = findEntities(searchableRow, table.getHeadline(), sectionNumber, localEntries); Set<Entity> rowEntities = findEntities(searchableRow, table.getHeadline(), sectionNumber, localEntries);
Section analysedRowSection = droolsExecutionService.executeRules(Section.builder() tableRowSections.add(new RowSectionPair(Section.builder()
.dictionaryService(dictionaryService) .dictionaryService(dictionaryService)
.entities(hintsPerSectionNumber != null && hintsPerSectionNumber.containsKey(sectionNumber) ? Stream .entities(hintsPerSectionNumber != null && hintsPerSectionNumber.containsKey(sectionNumber) ? Stream
.concat(rowEntities.stream(), hintsPerSectionNumber.get(sectionNumber).stream()) .concat(rowEntities.stream(), hintsPerSectionNumber.get(sectionNumber).stream())
@ -134,14 +136,18 @@ public class EntityRedactionService {
.headline(table.getHeadline()) .headline(table.getHeadline())
.sectionNumber(sectionNumber) .sectionNumber(sectionNumber)
.tabularData(tabularData) .tabularData(tabularData)
.build()); .build(), searchableRow));
documentEntities.addAll(clearAndFindPositions(analysedRowSection.getEntities(), searchableRow));
sectionNumber++; sectionNumber++;
} }
sectionNumber++; sectionNumber++;
} }
tableRowSections.forEach(rowSectionPair -> {
Section analysedRowSection = droolsExecutionService.executeRules(rowSectionPair.getSection());
documentEntities.addAll(clearAndFindPositions(analysedRowSection.getEntities(), rowSectionPair.getSearchableRow()));
});
addSectionToManualRedactions(paragraph.getTextBlocks(), manualRedactions, paragraph.getHeadline(), sectionNumber); addSectionToManualRedactions(paragraph.getTextBlocks(), manualRedactions, paragraph.getHeadline(), sectionNumber);
Set<Entity> entities = findEntities(searchableText, paragraph.getHeadline(), sectionNumber, localEntries); Set<Entity> entities = findEntities(searchableText, paragraph.getHeadline(), sectionNumber, localEntries);
Section analysedSection = droolsExecutionService.executeRules(Section.builder() Section analysedSection = droolsExecutionService.executeRules(Section.builder()

View File

@ -1,2 +1,10 @@
Long-term Long-term
Brown liquid Brown liquid
Brown solid
Hand-held
Manual-Hand held
Manual-Hand held
Weight:
Sprague
Weight and length
Aeration: Gentle