Search in sources :

Example 31 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class MappingProjectRepositoryImpl method toEntity.

/**
 * Creates a new Entity for a MappingProject. Upserts the {@link MappingProject}'s {@link MappingTarget}s in the
 * {@link #mappingTargetRepo}.
 *
 * @param mappingProject the {@link MappingProject} used to create an Entity
 * @return Entity filled with the data from the MappingProject
 */
private Entity toEntity(MappingProject mappingProject) {
    Entity result = new DynamicEntity(mappingProjectMeta);
    if (mappingProject.getIdentifier() == null) {
        mappingProject.setIdentifier(idGenerator.generateId());
    }
    result.set(MappingProjectMetaData.IDENTIFIER, mappingProject.getIdentifier());
    result.set(MappingProjectMetaData.OWNER, mappingProject.getOwner());
    result.set(MappingProjectMetaData.NAME, mappingProject.getName());
    List<Entity> mappingTargetEntities = mappingTargetRepo.upsert(mappingProject.getMappingTargets());
    result.set(MappingProjectMetaData.MAPPING_TARGETS, mappingTargetEntities);
    return result;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 32 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class OneToOneCategoryAlgorithmGeneratorTest method init.

@BeforeMethod
public void init() {
    dataService = Mockito.mock(DataService.class);
    categoryAlgorithmGenerator = new OneToOneCategoryAlgorithmGenerator(dataService);
    EntityType targetRefEntityType = createCategoricalRefEntityType("POTATO_REF");
    Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Almost daily + daily"));
    Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "Several times a week"));
    Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "About once a week"));
    Entity targetEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "Never + fewer than once a week"));
    Entity targetEntity5 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
    targetAttribute = attrMetaFactory.create().setName("Current Consumption Frequency of Potatoes").setDataType(CATEGORICAL);
    targetAttribute.setRefEntity(targetRefEntityType);
    Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3, targetEntity4, targetEntity5));
    targetEntityType = entityTypeFactory.create("target");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceRefEntityType = createCategoricalRefEntityType("LifeLines_POTATO_REF");
    Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Not this month"));
    Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1 day per month"));
    Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "2-3 days per month"));
    Entity sourceEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "1 day per week"));
    Entity sourceEntity5 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "2-3 days per week"));
    Entity sourceEntity6 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "4-5 days per week"));
    Entity sourceEntity7 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "6-7 days per week"));
    Entity sourceEntity8 = new DynamicEntity(targetRefEntityType, of("code", 8, "label", "9 days per week"));
    sourceAttribute = attrMetaFactory.create().setName("MESHED_POTATO").setDataType(CATEGORICAL);
    sourceAttribute.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
    sourceAttribute.setRefEntity(sourceRefEntityType);
    Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3, sourceEntity4, sourceEntity5, sourceEntity6, sourceEntity7, sourceEntity8));
    sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttributes(Lists.newArrayList(sourceAttribute));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class OneToOneCategoryAlgorithmGeneratorTest method testGenerateRules.

@Test
public void testGenerateRules() {
    EntityType targetRefEntityType = createCategoricalRefEntityType("HOP_HYPERTENSION");
    Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 0, "label", "Never had high blood pressure "));
    Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Ever had high blood pressure "));
    Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "Missing"));
    Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3));
    targetAttribute = attrMetaFactory.create().setName("History of Hypertension").setDataType(CATEGORICAL);
    targetAttribute.setRefEntity(targetRefEntityType);
    EntityType sourceRefEntityType = createCategoricalRefEntityType("High_blood_pressure_ref");
    Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes"));
    Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no"));
    Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "I do not know"));
    Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3));
    sourceAttribute = attrMetaFactory.create().setName("High_blood_pressure").setDataType(CATEGORICAL);
    sourceAttribute.setRefEntity(sourceRefEntityType);
    String generatedAlgorithm = categoryAlgorithmGenerator.generate(targetAttribute, singletonList(sourceAttribute), targetEntityType, sourceEntityType);
    String expectedAlgorithm = "$('High_blood_pressure').map({\"1\":\"1\",\"2\":\"0\",\"3\":\"9\"}, null, null).value();";
    Assert.assertEquals(generatedAlgorithm, expectedAlgorithm);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 34 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class CGDAnnotatorTest method annotateTestMatch.

@Test
public void annotateTestMatch() {
    EntityType emdIn = entityTypeFactory.create("Test");
    emdIn.addAttribute(attributeFactory.create().setName(GENE.getAttributeName()));
    emdIn.addAttribute(attributeFactory.create().setName(HGNC_ID.getAttributeName()).setDataType(STRING));
    emdIn.addAttribute(attributeFactory.create().setName(ENTREZ_GENE_ID.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(CONDITION.getAttributeName()).setDataType(TEXT).setLabel(CONDITION_LABEL));
    emdIn.addAttribute(attributeFactory.create().setName(INHERITANCE.getAttributeName()).setDataType(TEXT).setLabel(INHERITANCE_LABEL));
    emdIn.addAttribute(attributeFactory.create().setName(GENERALIZED_INHERITANCE.getAttributeName()).setDataType(TEXT).setLabel(GENERALIZED_INHERITANCE_LABEL));
    emdIn.addAttribute(attributeFactory.create().setName(AGE_GROUP.getAttributeName()).setDataType(TEXT).setLabel(AGE_GROUP_LABEL));
    emdIn.addAttribute(attributeFactory.create().setName(ALLELIC_CONDITIONS.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(MANIFESTATION_CATEGORIES.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(INTERVENTION_CATEGORIES.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(COMMENTS.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(INTERVENTION_RATIONALE.getAttributeName()).setDataType(TEXT));
    emdIn.addAttribute(attributeFactory.create().setName(REFERENCES.getAttributeName()).setDataType(TEXT));
    Entity inputEntity = new DynamicEntity(emdIn);
    inputEntity.set(GENE.getAttributeName(), "LEPR");
    Iterator<Entity> results = annotator.annotate(Collections.singletonList(inputEntity));
    assertTrue(results.hasNext());
    Entity resultEntity = results.next();
    assertFalse(results.hasNext());
    assertEquals(resultEntity.get(GENE.getAttributeName()), "LEPR");
    assertEquals(resultEntity.get(ENTREZ_GENE_ID.getAttributeName()), "3953");
    assertEquals(resultEntity.get(CONDITION.getAttributeName()), "Leptin receptor deficiency");
    assertEquals(resultEntity.get(INHERITANCE.getAttributeName()), "AR");
    assertEquals(resultEntity.get(AGE_GROUP.getAttributeName()), "Pediatric");
    assertEquals(resultEntity.get(ALLELIC_CONDITIONS.getAttributeName()), null);
    assertEquals(resultEntity.get(MANIFESTATION_CATEGORIES.getAttributeName()), "Allergy/Immunology/Infectious; Endocrine");
    assertEquals(resultEntity.get(INTERVENTION_CATEGORIES.getAttributeName()), "Allergy/Immunology/Infectious; Endocrine");
    assertEquals(resultEntity.get(COMMENTS.getAttributeName()), "Standard treatments for obesity, such as gastric surgery, have been described as beneficial");
    assertEquals(resultEntity.get(INTERVENTION_RATIONALE.getAttributeName()), "In addition to endocrine manifestations, individuals may be susceptible to infections (eg, respiratory infections), which, coupled with other manifestations (eg, severe obesity) can have severe sequelae such that prophylaxis and rapid treatment may be beneficial");
    assertEquals(resultEntity.get(REFERENCES.getAttributeName()), "8666155; 9537324; 17229951; 21306929; 23275530; 23616257");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 35 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class CGDAnnotatorTest method annotateTestNoMatch.

@Test
public void annotateTestNoMatch() {
    EntityType emdIn = entityTypeFactory.create("Test");
    emdIn.addAttribute(attributeFactory.create().setName(GENE.getAttributeName()));
    Entity inputEntity = new DynamicEntity(emdIn);
    inputEntity.set(GENE.getAttributeName(), "BOGUS");
    Iterator<Entity> results = annotator.annotate(Collections.singletonList(inputEntity));
    assertTrue(results.hasNext());
    Entity resultEntity = results.next();
    assertFalse(results.hasNext());
    assertEquals(resultEntity.get(GENE.getAttributeName()), "BOGUS");
    assertEquals(resultEntity.get(ENTREZ_GENE_ID.getAttributeName()), null);
    assertEquals(resultEntity.get(CONDITION.getAttributeName()), null);
    assertEquals(resultEntity.get(INHERITANCE.getAttributeName()), null);
    assertEquals(resultEntity.get(AGE_GROUP.getAttributeName()), null);
    assertEquals(resultEntity.get(ALLELIC_CONDITIONS.getAttributeName()), null);
    assertEquals(resultEntity.get(MANIFESTATION_CATEGORIES.getAttributeName()), null);
    assertEquals(resultEntity.get(INTERVENTION_CATEGORIES.getAttributeName()), null);
    assertEquals(resultEntity.get(COMMENTS.getAttributeName()), null);
    assertEquals(resultEntity.get(INTERVENTION_RATIONALE.getAttributeName()), null);
    assertEquals(resultEntity.get(REFERENCES.getAttributeName()), null);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3