DEV: Fixed Nullpointer on undefined color for type, adapted rule to Type naming.
This commit is contained in:
parent
c98f1d5e37
commit
49fe418a60
@ -175,7 +175,7 @@ public class AnnotationHighlightService {
|
||||
}
|
||||
if(entity.getType().equalsIgnoreCase("VERTEBRATE") || entity.getType().equalsIgnoreCase("NO_REDACTION_INDICATOR") ){
|
||||
// TODO in RED-161.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return dictionaryService.getDictionary().keySet().contains(entity.getType());
|
||||
}
|
||||
@ -184,6 +184,11 @@ public class AnnotationHighlightService {
|
||||
if (!entity.isRedaction()) {
|
||||
return new float[]{0.627f, 0.627f, 0.627f};
|
||||
}
|
||||
|
||||
if(!dictionaryService.getEntryColors().containsKey(entity.getType())){
|
||||
return dictionaryService.getEntryColors().get("default");
|
||||
}
|
||||
|
||||
return dictionaryService.getEntryColors().get(entity.getType());
|
||||
}
|
||||
|
||||
|
||||
@ -12,9 +12,9 @@ import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -33,9 +33,6 @@ import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.ResourceLoader;
|
||||
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.iqser.red.service.configuration.v1.api.model.DictionaryResponse;
|
||||
@ -47,6 +44,7 @@ import com.iqser.red.service.redaction.v1.model.RedactionResult;
|
||||
import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
|
||||
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
||||
import com.iqser.red.service.redaction.v1.server.controller.RedactionController;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.ResourceLoader;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.utils.TextNormalizationUtilities;
|
||||
|
||||
@Ignore
|
||||
@ -54,10 +52,11 @@ import com.iqser.red.service.redaction.v1.server.redaction.utils.TextNormalizati
|
||||
@SpringBootTest(webEnvironment = DEFINED_PORT)
|
||||
public class RedactionIntegrationTest {
|
||||
|
||||
public static final String VERTEBRATES_CODE = "VERTEBRATE";
|
||||
public static final String ADDRESS_CODE = "ADDRESS";
|
||||
public static final String NAME_CODE = "NAME";
|
||||
public static final String NO_REDACTION_INDICATOR = "NO_REDACTION_INDICATOR";
|
||||
public static final String VERTEBRATES_CODE = "vertebrate";
|
||||
public static final String ADDRESS_CODE = "address";
|
||||
public static final String NAME_CODE = "name";
|
||||
public static final String NO_REDACTION_INDICATOR = "no_redaction_indicator";
|
||||
public static final String DEFAULT = "default";
|
||||
|
||||
@Autowired
|
||||
private RedactionController redactionController;
|
||||
@ -104,6 +103,7 @@ public class RedactionIntegrationTest {
|
||||
when(dictionaryClient.getDictionaryForType(ADDRESS_CODE)).thenReturn(getDictionaryResponse(ADDRESS_CODE));
|
||||
when(dictionaryClient.getDictionaryForType(NAME_CODE)).thenReturn(getDictionaryResponse(NAME_CODE));
|
||||
when(dictionaryClient.getDictionaryForType(NO_REDACTION_INDICATOR)).thenReturn(getDictionaryResponse(NO_REDACTION_INDICATOR));
|
||||
when(dictionaryClient.getDictionaryForType(DEFAULT)).thenReturn(getDictionaryResponse(DEFAULT));
|
||||
}
|
||||
|
||||
private void loadDictionaryForTest() {
|
||||
@ -111,6 +111,7 @@ public class RedactionIntegrationTest {
|
||||
dictionary.computeIfAbsent(VERTEBRATES_CODE, v -> new ArrayList<>()).addAll(ResourceLoader.load("dictionaries/vertebrates.txt").stream().map(this::cleanDictionaryEntry).collect(Collectors.toSet()));
|
||||
dictionary.computeIfAbsent(ADDRESS_CODE, v -> new ArrayList<>()).addAll(ResourceLoader.load("dictionaries/addresses.txt").stream().map(this::cleanDictionaryEntry).collect(Collectors.toSet()));
|
||||
dictionary.computeIfAbsent(NO_REDACTION_INDICATOR, v -> new ArrayList<>()).addAll(ResourceLoader.load("dictionaries/NoRedactionIndicator.txt").stream().map(this::cleanDictionaryEntry).collect(Collectors.toSet()));
|
||||
dictionary.put(DEFAULT, new ArrayList<>());
|
||||
}
|
||||
|
||||
private String cleanDictionaryEntry(String entry) {
|
||||
@ -118,10 +119,11 @@ public class RedactionIntegrationTest {
|
||||
}
|
||||
|
||||
private void loadTypeForTest() {
|
||||
typeColorMap.put("VERTEBRATE", new float[]{0, 1, 0});
|
||||
typeColorMap.put("ADDRESS", new float[]{0, 1, 1});
|
||||
typeColorMap.put("NAME", new float[]{1, 1, 0});
|
||||
typeColorMap.put("NO_REDACTION_INDICATOR", new float[]{1, 0.502f, 0});
|
||||
typeColorMap.put(VERTEBRATES_CODE, new float[]{0, 1, 0});
|
||||
typeColorMap.put(ADDRESS_CODE, new float[]{0, 1, 1});
|
||||
typeColorMap.put(NAME_CODE, new float[]{1, 1, 0});
|
||||
typeColorMap.put(NO_REDACTION_INDICATOR, new float[]{1, 0.502f, 0});
|
||||
typeColorMap.put(DEFAULT, new float[]{1, 0.502f, 0});
|
||||
}
|
||||
|
||||
private List<TypeResult> getTypeResponse() {
|
||||
|
||||
@ -8,35 +8,35 @@ rule "0: Highlight Indicators"
|
||||
when
|
||||
eval(section.getEntities().isEmpty()==false);
|
||||
then
|
||||
section.highlightAll("VERTEBRATE");
|
||||
section.highlightAll("NO_REDACTION_INDICATOR");
|
||||
section.highlightAll("vertebrate");
|
||||
section.highlightAll("no_redaction_indicator");
|
||||
end
|
||||
|
||||
|
||||
rule "1: Redacted because Section contains Vertebrate"
|
||||
when
|
||||
eval(section.contains("VERTEBRATE")==true);
|
||||
eval(section.contains("vertebrate")==true);
|
||||
then
|
||||
section.redact("NAME", 1, "Redacted because Section contains Vertebrate");
|
||||
section.redact("ADDRESS", 1, "Redacted because Section contains Vertebrate");
|
||||
section.redact("name", 1, "Redacted because Section contains Vertebrate");
|
||||
section.redact("address", 1, "Redacted because Section contains Vertebrate");
|
||||
end
|
||||
|
||||
|
||||
rule "2: Not Redacted because Section contains no Vertebrate"
|
||||
when
|
||||
eval(section.contains("VERTEBRATE")==false);
|
||||
eval(section.contains("vertebrate")==false);
|
||||
then
|
||||
section.redactNot("NAME", 2, "Not Redacted because Section contains no Vertebrate");
|
||||
section.redactNot("ADDRESS", 2, "Not Redacted because Section contains no Vertebrate");
|
||||
section.redactNot("name", 2, "Not Redacted because Section contains no Vertebrate");
|
||||
section.redactNot("address", 2, "Not Redacted because Section contains no Vertebrate");
|
||||
end
|
||||
|
||||
|
||||
rule "3: Do not redact Names and Addresses if no redaction Indicator is contained"
|
||||
when
|
||||
eval(section.contains("VERTEBRATE")==true && section.contains("NO_REDACTION_INDICATOR")==true);
|
||||
eval(section.contains("vertebrate")==true && section.contains("no_redaction_indicator")==true);
|
||||
then
|
||||
section.redactNot("NAME", 3, "Vertebrate was found, but also a no redaction indicator");
|
||||
section.redactNot("ADDRESS", 3, "Vertebrate was found, but also a no redaction indicator");
|
||||
section.redactNot("name", 3, "Vertebrate was found, but also a no redaction indicator");
|
||||
section.redactNot("address", 3, "Vertebrate was found, but also a no redaction indicator");
|
||||
end
|
||||
|
||||
|
||||
@ -44,12 +44,12 @@ rule "4: Redact contact information, if applicant is found"
|
||||
when
|
||||
eval(section.getText().toLowerCase().contains("applicant"));
|
||||
then
|
||||
section.redactLineAfter("Name:", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactBetween("Address:", "Contact", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Contact point:", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Phone:", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Fax:", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("E-mail:", "ADDRESS", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Name:", "address", 4, "Redacted because of Rule 4");
|
||||
section.redactBetween("Address:", "Contact", "address", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Contact point:", "address", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Phone:", "address", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("Fax:", "address", 4, "Redacted because of Rule 4");
|
||||
section.redactLineAfter("E-mail:", "address", 4, "Redacted because of Rule 4");
|
||||
end
|
||||
|
||||
|
||||
@ -57,10 +57,10 @@ rule "5: Redact contact information, if 'Producer of the plant protection produc
|
||||
when
|
||||
eval(section.getText().contains("Producer of the plant protection product"));
|
||||
then
|
||||
section.redactLineAfter("Name:", "ADDRESS", 5, "xxxx");
|
||||
section.redactBetween("Address:", "Contact", "ADDRESS", 5, "xxxx");
|
||||
section.redactBetween("Contact:", "Phone", "ADDRESS", 5, "xxxx");
|
||||
section.redactLineAfter("Phone:", "ADDRESS", 5, "xxxx");
|
||||
section.redactLineAfter("Fax:", "ADDRESS", 5, "xxxx");
|
||||
section.redactLineAfter("E-mail:", "ADDRESS", 5, "xxxx");
|
||||
section.redactLineAfter("Name:", "address", 5, "xxxx");
|
||||
section.redactBetween("Address:", "Contact", "address", 5, "xxxx");
|
||||
section.redactBetween("Contact:", "Phone", "address", 5, "xxxx");
|
||||
section.redactLineAfter("Phone:", "address", 5, "xxxx");
|
||||
section.redactLineAfter("Fax:", "address", 5, "xxxx");
|
||||
section.redactLineAfter("E-mail:", "address", 5, "xxxx");
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user