Search in sources :

Example 11 with InvalidContent

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);
        }
    }
}
Also used : InvalidContent(org.ihtsdo.drools.response.InvalidContent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 12 with InvalidContent

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());
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) ConceptImpl(org.ihtsdo.drools.unittest.domain.ConceptImpl) InvalidContent(org.ihtsdo.drools.response.InvalidContent) DescriptionImpl(org.ihtsdo.drools.unittest.domain.DescriptionImpl) Test(org.junit.Test)

Example 13 with InvalidContent

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());
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) ConceptImpl(org.ihtsdo.drools.unittest.domain.ConceptImpl) InvalidContent(org.ihtsdo.drools.response.InvalidContent) DescriptionImpl(org.ihtsdo.drools.unittest.domain.DescriptionImpl) RelationshipImpl(org.ihtsdo.drools.unittest.domain.RelationshipImpl) Test(org.junit.Test)

Example 14 with InvalidContent

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());
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) ConceptImpl(org.ihtsdo.drools.unittest.domain.ConceptImpl) InvalidContent(org.ihtsdo.drools.response.InvalidContent) DescriptionImpl(org.ihtsdo.drools.unittest.domain.DescriptionImpl) RelationshipImpl(org.ihtsdo.drools.unittest.domain.RelationshipImpl) Test(org.junit.Test)

Example 15 with InvalidContent

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;
}
Also used : InvalidContent(org.ihtsdo.drools.response.InvalidContent)

Aggregations

InvalidContent (org.ihtsdo.drools.response.InvalidContent)15 Concept (org.ihtsdo.drools.domain.Concept)3 ConceptImpl (org.ihtsdo.drools.unittest.domain.ConceptImpl)3 DescriptionImpl (org.ihtsdo.drools.unittest.domain.DescriptionImpl)3 Test (org.junit.Test)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RelationshipImpl (org.ihtsdo.drools.unittest.domain.RelationshipImpl)2 DroolsConcept (org.ihtsdo.drools.validator.rf2.domain.DroolsConcept)2 DroolsConceptService (org.ihtsdo.drools.validator.rf2.service.DroolsConceptService)2 DroolsDescriptionService (org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService)2 DroolsRelationshipService (org.ihtsdo.drools.validator.rf2.service.DroolsRelationshipService)2 DroolsConcept (org.snomed.snowstorm.validation.domain.DroolsConcept)2 BranchCriteria (io.kaicode.elasticvc.api.BranchCriteria)1 Branch (io.kaicode.elasticvc.domain.Branch)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Callable (java.util.concurrent.Callable)1