Search in sources :

Example 1 with DroolsConcept

use of org.ihtsdo.drools.validator.rf2.domain.DroolsConcept in project snomed-drools by IHTSDO.

the class DroolsConceptServiceTest method testFindStatedAncestorsOfConcept.

@Test
public void testFindStatedAncestorsOfConcept() {
    Concept concept = new DroolsConcept("1263005", true, "900000000000207008", "900000000000073002", true, true);
    Set<String> results = droolsConceptService.findStatedAncestorsOfConcept(concept);
    Assert.assertEquals(7, results.size());
    concept = new DroolsConcept("91832008", true, "900000000000207008", "900000000000073002", true, true);
    results = droolsConceptService.findStatedAncestorsOfConcept(concept);
    Assert.assertEquals(2, results.size());
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) Test(org.junit.Test)

Example 2 with DroolsConcept

use of org.ihtsdo.drools.validator.rf2.domain.DroolsConcept in project snomed-drools by IHTSDO.

the class DroolsConceptService method findStatedAncestorsOfConcept.

@Override
public Set<String> findStatedAncestorsOfConcept(Concept concept) {
    if (concept == null || concept.getId().equals(Constants.ROOT_CONCEPT)) {
        return Collections.emptySet();
    }
    DroolsConcept droolsConcept = repository.getConcept(concept.getId());
    Set<String> statedParents = new HashSet<>();
    for (DroolsRelationship relationship : droolsConcept.getRelationships()) {
        if (relationship.isActive() && !relationship.isAxiomGCI() && Constants.IS_A.equals(relationship.getTypeId()) && Constants.STATED_RELATIONSHIP.equals(relationship.getCharacteristicTypeId())) {
            statedParents.add(relationship.getDestinationId());
        }
    }
    Set<String> resultSet = new HashSet<>(statedParents);
    for (String statedParent : statedParents) {
        resultSet.addAll(findStatedAncestorsOfConcept(repository.getConcept(statedParent)));
    }
    return resultSet;
}
Also used : DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) DroolsRelationship(org.ihtsdo.drools.validator.rf2.domain.DroolsRelationship) HashSet(java.util.HashSet)

Example 3 with DroolsConcept

use of org.ihtsdo.drools.validator.rf2.domain.DroolsConcept in project snomed-drools by IHTSDO.

the class BaseServiceTest method loadConceptsIntoRepository.

protected void loadConceptsIntoRepository() throws FileNotFoundException {
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/138875005.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/1263005.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/91832008.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/123037004.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/4421005.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/67185001.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/91723000.json", DroolsConcept.class));
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/442083009.json", DroolsConcept.class));
    repository.addConcept(new DroolsConcept("12345678", true, "900000000000207008", "900000000000073002", true, true));
}
Also used : DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept)

Example 4 with DroolsConcept

use of org.ihtsdo.drools.validator.rf2.domain.DroolsConcept in project snomed-drools by IHTSDO.

the class DroolsDescriptionServiceTest method testFindMatchingDescriptionsInHierachy.

@Test
public void testFindMatchingDescriptionsInHierachy() throws FileNotFoundException {
    // load a dummy concept which has duplicated description term with its parent
    repository.addConcept(FileLoaderTestUtils.fileToObject("data/1234567890.json", DroolsConcept.class));
    DroolsConcept testConcept = repository.getConcept("1234567890");
    DroolsDescription testDescription = null;
    for (DroolsDescription droolsDescription : testConcept.getDescriptions()) {
        testDescription = droolsDescription;
    }
    Set<Description> results = droolsDescriptionService.findMatchingDescriptionInHierarchy(testConcept, testDescription);
    Assert.assertEquals(1, results.size());
    for (Description result : results) {
        Assert.assertEquals("1204236014", result.getId());
    }
}
Also used : DroolsDescription(org.ihtsdo.drools.validator.rf2.domain.DroolsDescription) Description(org.ihtsdo.drools.domain.Description) DroolsDescription(org.ihtsdo.drools.validator.rf2.domain.DroolsDescription) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) Test(org.junit.Test)

Example 5 with DroolsConcept

use of org.ihtsdo.drools.validator.rf2.domain.DroolsConcept in project snomed-drools by IHTSDO.

the class DroolsRF2Validator method validateSnapshot.

public List<InvalidContent> validateSnapshot(InputStream snomedRf2EditionZip, Set<String> ruleSetNamesToRun) throws ReleaseImportException {
    long start = new Date().getTime();
    Assert.isTrue(ruleSetNamesToRun != null && !ruleSetNamesToRun.isEmpty(), "The name of at least one rule set must be specified.");
    ReleaseImporter importer = new ReleaseImporter();
    SnomedDroolsComponentRepository repository = new SnomedDroolsComponentRepository();
    logger.info("Loading components from RF2");
    LoadingProfile loadingProfile = LoadingProfile.complete;
    loadingProfile.getIncludedReferenceSetFilenamePatterns().add(".*_cRefset_Language.*");
    importer.loadSnapshotReleaseFiles(snomedRf2EditionZip, loadingProfile, new SnomedDroolsComponentFactory(repository));
    logger.info("Components loaded");
    DroolsConceptService conceptService = new DroolsConceptService(repository);
    DroolsDescriptionService descriptionService = new DroolsDescriptionService(repository);
    DroolsRelationshipService relationshipService = new DroolsRelationshipService(repository);
    Collection<DroolsConcept> concepts = repository.getConcepts();
    logger.info("Running tests");
    List<InvalidContent> invalidContents = ruleExecutor.execute(ruleSetNamesToRun, concepts, conceptService, descriptionService, relationshipService, true, false);
    logger.info("Tests complete. Total run time {} seconds", (new Date().getTime() - start) / 1000);
    logger.info("invalidContent count {}", invalidContents.size());
    return invalidContents;
}
Also used : ReleaseImporter(org.ihtsdo.otf.snomedboot.ReleaseImporter) InvalidContent(org.ihtsdo.drools.response.InvalidContent) DroolsDescriptionService(org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) DroolsConceptService(org.ihtsdo.drools.validator.rf2.service.DroolsConceptService) DroolsRelationshipService(org.ihtsdo.drools.validator.rf2.service.DroolsRelationshipService) LoadingProfile(org.ihtsdo.otf.snomedboot.factory.LoadingProfile)

Aggregations

DroolsConcept (org.ihtsdo.drools.validator.rf2.domain.DroolsConcept)14 DroolsRelationship (org.ihtsdo.drools.validator.rf2.domain.DroolsRelationship)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Concept (org.ihtsdo.drools.domain.Concept)2 InvalidContent (org.ihtsdo.drools.response.InvalidContent)2 DroolsDescription (org.ihtsdo.drools.validator.rf2.domain.DroolsDescription)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 Description (org.ihtsdo.drools.domain.Description)1 DroolsOntologyAxiom (org.ihtsdo.drools.validator.rf2.domain.DroolsOntologyAxiom)1 ReleaseImporter (org.ihtsdo.otf.snomedboot.ReleaseImporter)1 LoadingProfile (org.ihtsdo.otf.snomedboot.factory.LoadingProfile)1