Fix test and suppress checkstyle warnings
This commit is contained in:
parent
d97a7b629a
commit
a6415363cd
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.iqser.red.service.redaction.v1.server.parsing.model.TextPositionSequence;
|
import com.iqser.red.service.redaction.v1.server.parsing.model.TextPositionSequence;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.TextNormalizationUtilities;
|
import com.iqser.red.service.redaction.v1.server.redaction.utils.TextNormalizationUtilities;
|
||||||
@ -26,6 +25,7 @@ public class SearchableText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("checkstyle:ModifiedControlVariable")
|
||||||
public List<EntityPositionSequence> getSequences(String searchString, boolean caseInsensitive) {
|
public List<EntityPositionSequence> getSequences(String searchString, boolean caseInsensitive) {
|
||||||
|
|
||||||
String normalizedSearchString;
|
String normalizedSearchString;
|
||||||
@ -64,9 +64,9 @@ public class SearchableText {
|
|||||||
.charAt(j, caseInsensitive) == '-') {
|
.charAt(j, caseInsensitive) == '-') {
|
||||||
|
|
||||||
if (counter != 0 || i == 0 && j == 0 || j != 0 && isSeparator(sequences.get(i)
|
if (counter != 0 || i == 0 && j == 0 || j != 0 && isSeparator(sequences.get(i)
|
||||||
.charAt(j - 1, caseInsensitive)) || j == 0 && isSeparator(sequences.get(i - 1)
|
.charAt(j - 1, caseInsensitive)) || j == 0 && i != 0 && isSeparator(sequences.get(i - 1)
|
||||||
.charAt(sequences.get(i - 1)
|
.charAt(sequences.get(i - 1)
|
||||||
.length() - 1, caseInsensitive)) || j == 0 && sequences.get(i - 1)
|
.length() - 1, caseInsensitive)) || j == 0 && i != 0 && sequences.get(i - 1)
|
||||||
.charAt(sequences.get(i - 1).length() - 1, caseInsensitive) != ' ' && sequences.get(i)
|
.charAt(sequences.get(i - 1).length() - 1, caseInsensitive) != ' ' && sequences.get(i)
|
||||||
.charAt(j, caseInsensitive) != ' ') {
|
.charAt(j, caseInsensitive) != ' ') {
|
||||||
partMatch.add(sequences.get(i).textPositionAt(j));
|
partMatch.add(sequences.get(i).textPositionAt(j));
|
||||||
@ -187,10 +187,4 @@ public class SearchableText {
|
|||||||
return sb.append("\n").toString();
|
return sb.append("\n").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getAsTabularData() {
|
|
||||||
|
|
||||||
return sequences.stream().map(TextPositionSequence::toString).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -7,9 +7,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class EntityRedactionService {
|
|||||||
SearchableText searchableRow = new SearchableText();
|
SearchableText searchableRow = new SearchableText();
|
||||||
List<String> cellValues = new ArrayList<>();
|
List<String> cellValues = new ArrayList<>();
|
||||||
for (Cell cell : row) {
|
for (Cell cell : row) {
|
||||||
if (cell == null || cell.getTextBlocks() == null) {
|
if (cell == null || CollectionUtils.isEmpty(cell.getTextBlocks())) {
|
||||||
cellValues.add(null);
|
cellValues.add(null);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -113,7 +112,16 @@ public class EntityRedactionService {
|
|||||||
|
|
||||||
private Map<String, String> toMap(List<String> keys, List<String> values) {
|
private Map<String, String> toMap(List<String> keys, List<String> values) {
|
||||||
|
|
||||||
return IntStream.range(0, keys.size()).boxed().collect(Collectors.toMap(keys::get, values::get));
|
if (keys.size() != values.size()) {
|
||||||
|
throw new RuntimeException("Cannot merge lists of unequal size.");
|
||||||
|
}
|
||||||
|
Map<String, String> result = new HashMap<>();
|
||||||
|
for (int i = 0; i < keys.size(); i++) {
|
||||||
|
result.put(keys.get(i), values.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -41,13 +41,14 @@ public class SectionsBuilderService {
|
|||||||
Paragraph chunkBlock = buildTextBlock(chunkWords, lastHeadline, previousTable);
|
Paragraph chunkBlock = buildTextBlock(chunkWords, lastHeadline, previousTable);
|
||||||
chunkBlock.setHeadline(lastHeadline);
|
chunkBlock.setHeadline(lastHeadline);
|
||||||
lastHeadline = current.getText();
|
lastHeadline = current.getText();
|
||||||
|
if (CollectionUtils.isNotEmpty(chunkBlock.getTables())) {
|
||||||
|
previousTable = chunkBlock.getTables().get(0);
|
||||||
|
}
|
||||||
chunkBlockList.add(chunkBlock);
|
chunkBlockList.add(chunkBlock);
|
||||||
chunkWords = new ArrayList<>();
|
chunkWords = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkWords.add(current);
|
chunkWords.add(current);
|
||||||
|
|
||||||
prev = current;
|
prev = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +96,6 @@ public class SectionsBuilderService {
|
|||||||
alreadyAdded = true;
|
alreadyAdded = true;
|
||||||
}
|
}
|
||||||
paragraph.getPageBlocks().add(table);
|
paragraph.getPageBlocks().add(table);
|
||||||
previousTable = table;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public class Table extends AbstractTextContainer {
|
|||||||
boolean allBold = true;
|
boolean allBold = true;
|
||||||
List<Cell> rowCells = rows.get(0);
|
List<Cell> rowCells = rows.get(0);
|
||||||
for (Cell cell : rowCells) {
|
for (Cell cell : rowCells) {
|
||||||
if (CollectionUtils.isNotEmpty(cell.getTextBlocks()) &&
|
if (cell == null || CollectionUtils.isEmpty(cell.getTextBlocks()) ||
|
||||||
!cell.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
|
!cell.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
|
||||||
allBold = false;
|
allBold = false;
|
||||||
break;
|
break;
|
||||||
@ -93,7 +93,7 @@ public class Table extends AbstractTextContainer {
|
|||||||
List<Cell> firstColCells = new ArrayList<>();
|
List<Cell> firstColCells = new ArrayList<>();
|
||||||
for (List<Cell> row : rows) {
|
for (List<Cell> row : rows) {
|
||||||
Cell firstInRow = row.get(0);
|
Cell firstInRow = row.get(0);
|
||||||
if (CollectionUtils.isNotEmpty(firstInRow.getTextBlocks()) &&
|
if (firstInRow == null || CollectionUtils.isEmpty(firstInRow.getTextBlocks()) ||
|
||||||
!firstInRow.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
|
!firstInRow.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
|
||||||
allBold = false;
|
allBold = false;
|
||||||
break;
|
break;
|
||||||
@ -113,7 +113,7 @@ public class Table extends AbstractTextContainer {
|
|||||||
} else {
|
} else {
|
||||||
log.info("Headers are defaulted in first row.");
|
log.info("Headers are defaulted in first row.");
|
||||||
return rowCells.stream().map(cell -> {
|
return rowCells.stream().map(cell -> {
|
||||||
if (CollectionUtils.isNotEmpty(cell.getTextBlocks())) {
|
if (cell != null && CollectionUtils.isNotEmpty(cell.getTextBlocks())) {
|
||||||
return cell.getTextBlocks().get(0).getText();
|
return cell.getTextBlocks().get(0).getText();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -171,7 +171,7 @@ public class Table extends AbstractTextContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(Cell chunk, int row, int col) {
|
private void add(Cell chunk, int row, int col) {
|
||||||
|
|
||||||
rowCount = Math.max(rowCount, row + 1);
|
rowCount = Math.max(rowCount, row + 1);
|
||||||
colCount = Math.max(colCount, col + 1);
|
colCount = Math.max(colCount, col + 1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user