Fix style.
This commit is contained in:
parent
9a425a8594
commit
33ab09d7fc
@ -25,11 +25,15 @@ 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);
|
||||||
@ -39,7 +43,9 @@ 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);
|
||||||
@ -49,6 +55,7 @@ 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");
|
||||||
@ -70,7 +77,6 @@ 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);
|
||||||
@ -91,8 +97,6 @@ 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<>();
|
||||||
@ -103,14 +107,12 @@ public class Section {
|
|||||||
startIndex = searchText.indexOf(value, stopIndex);
|
startIndex = searchText.indexOf(value, stopIndex);
|
||||||
stopIndex = startIndex + value.length();
|
stopIndex = startIndex + value.length();
|
||||||
|
|
||||||
if (startIndex > -1 &&
|
if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(searchText.charAt(startIndex - 1)) || isSeparator(searchText
|
||||||
(startIndex == 0 || Character.isWhitespace(searchText.charAt(startIndex - 1)) || isSeparator(searchText.charAt(startIndex - 1))) &&
|
.charAt(startIndex - 1))) && (stopIndex == searchText.length() || isSeparator(searchText.charAt(stopIndex)))) {
|
||||||
(stopIndex == searchText.length() || isSeparator(searchText.charAt(stopIndex)))) {
|
|
||||||
found.add(new Entity(searchText.substring(startIndex, stopIndex), asType, startIndex, stopIndex, headline));
|
found.add(new Entity(searchText.substring(startIndex, stopIndex), asType, startIndex, stopIndex, headline));
|
||||||
}
|
}
|
||||||
} while (startIndex > -1);
|
} while (startIndex > -1);
|
||||||
|
|
||||||
|
|
||||||
removeEntitiesContainedInLarger(found);
|
removeEntitiesContainedInLarger(found);
|
||||||
|
|
||||||
return found;
|
return 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user