Fix style.

This commit is contained in:
Thierry Göckel 2020-07-23 13:35:58 +02:00
parent 9a425a8594
commit 33ab09d7fc
2 changed files with 38 additions and 33 deletions

View File

@ -25,13 +25,17 @@ public class Section {
private String headline; private String headline;
public boolean contains(String type) { public boolean contains(String type) {
return entities.stream().anyMatch(entity -> entity.getType().equals(type)); return entities.stream().anyMatch(entity -> entity.getType().equals(type));
} }
public void redact(String type, int ruleNumber, String reason){
public void redact(String type, int ruleNumber, String reason) {
entities.forEach(entity -> { entities.forEach(entity -> {
if(entity.getType().equals(type)){ if (entity.getType().equals(type)) {
entity.setRedaction(true); entity.setRedaction(true);
entity.setMatchedRule(ruleNumber); entity.setMatchedRule(ruleNumber);
entity.setRedactionReason(reason); entity.setRedactionReason(reason);
@ -39,9 +43,11 @@ public class Section {
}); });
} }
public void redactNot(String type, int ruleNumber, String reason){
public void redactNot(String type, int ruleNumber, String reason) {
entities.forEach(entity -> { entities.forEach(entity -> {
if(entity.getType().equals(type)){ if (entity.getType().equals(type)) {
entity.setRedaction(false); entity.setRedaction(false);
entity.setMatchedRule(ruleNumber); entity.setMatchedRule(ruleNumber);
entity.setRedactionReason(reason); entity.setRedactionReason(reason);
@ -49,18 +55,19 @@ public class Section {
}); });
} }
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");
if(value != null){ if (value != null) {
Set<Entity> found = findEntity(value.trim(), asType); Set<Entity> found = findEntity(value.trim(), asType);
entities.addAll(found); entities.addAll(found);
} }
// TODO No need to iterate // TODO No need to iterate
entities.forEach(entity -> { entities.forEach(entity -> {
if(entity.getType().equals(asType)){ if (entity.getType().equals(asType)) {
entity.setRedaction(true); entity.setRedaction(true);
entity.setMatchedRule(ruleNumber); entity.setMatchedRule(ruleNumber);
entity.setRedactionReason(reason); entity.setRedactionReason(reason);
@ -70,19 +77,18 @@ public class Section {
} }
public void redactBetween(String start, String stop, String asType, int ruleNumber, String reason) {
public void redactBetween(String start, String stop, String asType, int ruleNumber, String reason){
String value = StringUtils.substringBetween(searchText, start, stop); String value = StringUtils.substringBetween(searchText, start, stop);
if(value != null){ if (value != null) {
Set<Entity> found = findEntity(value.trim(), asType); Set<Entity> found = findEntity(value.trim(), asType);
entities.addAll(found); entities.addAll(found);
} }
// TODO No need to iterate // TODO No need to iterate
entities.forEach(entity -> { entities.forEach(entity -> {
if(entity.getType().equals(asType)){ if (entity.getType().equals(asType)) {
entity.setRedaction(true); entity.setRedaction(true);
entity.setMatchedRule(ruleNumber); entity.setMatchedRule(ruleNumber);
entity.setRedactionReason(reason); entity.setRedactionReason(reason);
@ -91,25 +97,21 @@ public class Section {
} }
private Set<Entity> findEntity(String value, String asType) { private Set<Entity> findEntity(String value, String asType) {
Set<Entity> found = new HashSet<>(); Set<Entity> found = new HashSet<>();
int startIndex; int startIndex;
int stopIndex = 0; int stopIndex = 0;
do { do {
startIndex = searchText.indexOf(value, stopIndex); startIndex = searchText.indexOf(value, stopIndex);
stopIndex = startIndex + value.length(); stopIndex = startIndex + value.length();
if (startIndex > -1 &&
(startIndex == 0 || Character.isWhitespace(searchText.charAt(startIndex - 1)) || isSeparator(searchText.charAt(startIndex - 1))) &&
(stopIndex == searchText.length() || isSeparator(searchText.charAt(stopIndex)))) {
found.add(new Entity(searchText.substring(startIndex, stopIndex), asType, startIndex, stopIndex, headline));
}
} while (startIndex > -1);
if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(searchText.charAt(startIndex - 1)) || isSeparator(searchText
.charAt(startIndex - 1))) && (stopIndex == searchText.length() || isSeparator(searchText.charAt(stopIndex)))) {
found.add(new Entity(searchText.substring(startIndex, stopIndex), asType, startIndex, stopIndex, headline));
}
} while (startIndex > -1);
removeEntitiesContainedInLarger(found); removeEntitiesContainedInLarger(found);
@ -118,14 +120,18 @@ public class Section {
private boolean isSeparator(char c) { private boolean isSeparator(char c) {
return Character.isWhitespace(c) || Pattern.matches("\\p{Punct}", String.valueOf(c)) || c == '\"' || c == '' || c == ''; return Character.isWhitespace(c) || Pattern.matches("\\p{Punct}", String.valueOf(c)) || c == '\"' || c == '' || c == '';
} }
public void removeEntitiesContainedInLarger(Set<Entity> entities) { public void removeEntitiesContainedInLarger(Set<Entity> entities) {
List<Entity> wordsToRemove = new ArrayList<>(); List<Entity> wordsToRemove = new ArrayList<>();
for (Entity word : entities) { for (Entity word : entities) {
for (Entity inner : entities) { for (Entity inner : entities) {
if (inner.getWord().length() < word.getWord().length() && inner.getStart() >= word.getStart() && inner.getEnd() <= word.getEnd() && word != inner) { if (inner.getWord().length() < word.getWord()
.length() && inner.getStart() >= word.getStart() && inner.getEnd() <= word.getEnd() && word != inner) {
wordsToRemove.add(inner); wordsToRemove.add(inner);
} }
} }

View File

@ -2,6 +2,7 @@ package com.iqser.red.service.redaction.v1.server.redaction.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -55,16 +56,14 @@ public class DictionaryService {
try { try {
TypeResponse typeResponse = dictionaryClient.getAllTypes(); TypeResponse typeResponse = dictionaryClient.getAllTypes();
if (typeResponse != null && !CollectionUtils.isEmpty(typeResponse.getTypes())) { if (typeResponse != null && CollectionUtils.isNotEmpty(typeResponse.getTypes())) {
entryColors = typeResponse.getTypes() entryColors = typeResponse.getTypes()
.stream() .stream()
.collect(Collectors.toMap(TypeResult::getType, TypeResult::getColor)); .collect(Collectors.toMap(TypeResult::getType, TypeResult::getColor));
dictionary = entryColors.keySet() dictionary = entryColors.keySet()
.stream() .stream()
.collect(Collectors.toMap(type -> type, s -> dictionaryClient.getDictionaryForType(s) .collect(Collectors.toMap(type -> type, s -> new HashSet<>(dictionaryClient.getDictionaryForType(s)
.getEntries() .getEntries())));
.stream()
.collect(Collectors.toSet())));
hintTypes = typeResponse.getTypes() hintTypes = typeResponse.getTypes()
.stream() .stream()
.filter(TypeResult::isHint) .filter(TypeResult::isHint)