use of org.ihtsdo.drools.response.InvalidContent in project snomed-drools by IHTSDO.
the class IntegrationManualTest method main.
public static void main(String[] args) throws IOException, ReleaseImportException {
String releaseFilePath = "/path/to/all-files";
String directoryOfRuleSetsPath = "path/to/rules";
Set<String> ruleSetNamesToRun = Sets.newHashSet("common-authoring,int-authoring".split(","));
final String currentEffectiveTime = "20200131";
Set<String> includedModulesSet = Sets.newHashSet();
List<InvalidContent> invalidContents = new DroolsRF2Validator(directoryOfRuleSetsPath, false).validateRF2Files(Collections.singleton(copyRF2RemovingComments(releaseFilePath)), null, ruleSetNamesToRun, currentEffectiveTime, includedModulesSet, false);
// Some extra output when running this main method in development -
int outputSize = Math.min(invalidContents.size(), 50);
System.out.println("First 50 failures:");
for (InvalidContent invalidContent : invalidContents.subList(0, outputSize)) {
System.out.println(invalidContent);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter("errors.txt"))) {
writer.write("Severity\tMessage\tConceptId\tComponentId");
writer.newLine();
System.out.println();
System.out.println("Failure counts by assertion:");
Map<String, AtomicInteger> failureCounts = new HashMap<>();
for (InvalidContent invalidContent : invalidContents) {
String message = invalidContent.getSeverity().toString() + " - " + invalidContent.getMessage();
AtomicInteger atomicInteger = failureCounts.get(message);
if (atomicInteger == null) {
atomicInteger = new AtomicInteger();
failureCounts.put(message, atomicInteger);
}
atomicInteger.incrementAndGet();
// also write out all errors
if (invalidContent.getSeverity() == ERROR) {
writer.write(invalidContent.getSeverity() + "\t" + invalidContent.getMessage() + "\t" + invalidContent.getConceptId() + "\t" + invalidContent.getComponentId());
writer.newLine();
}
}
for (String errorMessage : failureCounts.keySet()) {
System.out.println(failureCounts.get(errorMessage).toString() + " - " + errorMessage);
}
}
}
use of org.ihtsdo.drools.response.InvalidContent in project snomed-drools by IHTSDO.
the class RuleExecutorTest method testExecuteIgnorePublishedContentCheck.
@Test
public void testExecuteIgnorePublishedContentCheck() throws Exception {
final Concept concept = new ConceptImpl("1").addDescription(new DescriptionImpl("2", "a").published().addToAcceptability("900000000000508004", "PREFERRED"));
final List<InvalidContent> invalidContent = ruleExecutor.execute(RULE_SET_NAMES, Collections.singleton(concept), conceptService, descriptionService, relationshipService, false, false);
Assert.assertEquals(1, invalidContent.size());
final InvalidContent invalidContent1 = invalidContent.get(0);
Assert.assertEquals(concept.getId(), invalidContent1.getConceptId());
Assert.assertEquals("Term should have acceptability entries in one dialect.", invalidContent1.getMessage());
Assert.assertEquals("2", invalidContent1.getComponentId());
}
use of org.ihtsdo.drools.response.InvalidContent in project snomed-drools by IHTSDO.
the class RuleExecutorTest method testExecute.
@Test
public void testExecute() {
final Concept concept = new ConceptImpl("1").addDescription(new DescriptionImpl("2", "a ")).addRelationship(new RelationshipImpl("r1", "3")).addRelationship(new RelationshipImpl("r2", "4"));
final List<InvalidContent> invalidContent = ruleExecutor.execute(RULE_SET_NAMES, Collections.singleton(concept), conceptService, descriptionService, relationshipService, true, false);
Assert.assertEquals(1, invalidContent.size());
final InvalidContent invalidContent1 = invalidContent.get(0);
Assert.assertEquals(concept.getId(), invalidContent1.getConceptId());
Assert.assertEquals("Term should not contain double spaces.", invalidContent1.getMessage());
Assert.assertEquals("2", invalidContent1.getComponentId());
}
use of org.ihtsdo.drools.response.InvalidContent in project snomed-drools by IHTSDO.
the class RuleExecutorTest method testExecuteOnlyUnpublishedContent.
@Test
public void testExecuteOnlyUnpublishedContent() throws Exception {
final Concept concept = new ConceptImpl("1").addDescription(new DescriptionImpl("2", "a ").published()).addRelationship(new RelationshipImpl("r1", "3")).addRelationship(new RelationshipImpl("r2", "4"));
final List<InvalidContent> invalidContent = ruleExecutor.execute(RULE_SET_NAMES, Collections.singleton(concept), conceptService, descriptionService, relationshipService, false, false);
Assert.assertEquals(0, invalidContent.size());
}
use of org.ihtsdo.drools.response.InvalidContent in project snomed-drools by IHTSDO.
the class RuleExecutor method removeDuplicates.
private List<InvalidContent> removeDuplicates(List<InvalidContent> invalidContent) {
List<InvalidContent> uniqueInvalidContent = new ArrayList<>();
Map<String, Map<String, Set<String>>> conceptComponentMessageMap = new HashMap<>();
for (InvalidContent content : invalidContent) {
Map<String, Set<String>> componentMessages = conceptComponentMessageMap.computeIfAbsent(content.getConceptId(), s -> new HashMap<>());
Set<String> messages = componentMessages.computeIfAbsent(content.getComponentId(), s -> new HashSet<>());
if (messages.add(content.getMessage())) {
uniqueInvalidContent.add(content);
}
}
return uniqueInvalidContent;
}
Aggregations