Use void method type
This commit is contained in:
parent
b1a266d4d4
commit
470665cc8f
@ -73,7 +73,7 @@ public class DictionaryService {
|
|||||||
.filter(TypeResult::isCaseInsensitive)
|
.filter(TypeResult::isCaseInsensitive)
|
||||||
.map(TypeResult::getType)
|
.map(TypeResult::getType)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dictionary = entryColors.keySet().stream().collect(Collectors.toMap(type -> type, s -> convertEntries(s)));
|
dictionary = entryColors.keySet().stream().collect(Collectors.toMap(type -> type, this::convertEntries));
|
||||||
defaultColor = dictionaryClient.getDefaultColor().getColor();
|
defaultColor = dictionaryClient.getDefaultColor().getColor();
|
||||||
}
|
}
|
||||||
} catch (FeignException e) {
|
} catch (FeignException e) {
|
||||||
|
|||||||
@ -103,9 +103,9 @@ public class EntityRedactionService {
|
|||||||
|
|
||||||
private Set<Entity> clearAndFindPositions(Set<Entity> entities, SearchableText text) {
|
private Set<Entity> clearAndFindPositions(Set<Entity> entities, SearchableText text) {
|
||||||
|
|
||||||
Set<Entity> cleanEntities = removeEntitiesContainedInLarger(entities);
|
removeEntitiesContainedInLarger(entities);
|
||||||
|
|
||||||
for (Entity entity : cleanEntities) {
|
for (Entity entity : entities) {
|
||||||
if (dictionaryService.getCaseInsensitiveTypes().contains(entity.getType())) {
|
if (dictionaryService.getCaseInsensitiveTypes().contains(entity.getType())) {
|
||||||
entity.setPositionSequences(text.getSequences(entity.getWord(), true));
|
entity.setPositionSequences(text.getSequences(entity.getWord(), true));
|
||||||
} else {
|
} else {
|
||||||
@ -113,7 +113,7 @@ public class EntityRedactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanEntities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,7 +132,10 @@ public class EntityRedactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return removeEntitiesContainedInLarger(found);
|
removeEntitiesContainedInLarger(found);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,7 +165,7 @@ public class EntityRedactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<Entity> 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) {
|
||||||
@ -174,7 +177,6 @@ public class EntityRedactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
entities.removeAll(wordsToRemove);
|
entities.removeAll(wordsToRemove);
|
||||||
return entities;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.server.redaction.service;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.kie.api.runtime.KieContainer;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.iqser.red.service.redaction.v1.server.redaction.model.Entity;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class EntityRedactionServiceTest {
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private KieContainer kieContainer;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private DroolsExecutionService droolsExecutionService;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private DictionaryService dictionaryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EntityRedactionService entityRedactionService;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNestedEntitiesRemoval() {
|
||||||
|
|
||||||
|
Set<Entity> entities = new HashSet<>();
|
||||||
|
Entity nested = new Entity("nested", "fake type", 10, 16, "fake headline", 0);
|
||||||
|
Entity nesting = new Entity("nesting nested", "fake type", 2, 16, "fake headline", 0);
|
||||||
|
entities.add(nested);
|
||||||
|
entities.add(nesting);
|
||||||
|
entityRedactionService.removeEntitiesContainedInLarger(entities);
|
||||||
|
|
||||||
|
assertThat(entities.size()).isEqualTo(1);
|
||||||
|
assertThat(entities).contains(nesting);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user